Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105).
Print a single integer — the maximum number of points that Alex can earn.
2 1 2
2
3 1 2 3
4
9 1 2 1 3 2 2 2 2 3
10
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this[2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
题意:
给出 n(1 ~ 10 ^ 5) 个数,后给出这 n 个数,每次取一个数 k,取的同时,k - 1 与 k + 1 也会消失。每次取的数为本次取的分数,最后使求和的结果最大。
思路:
DP。dp [ i ] = MAX { dp [ i - 1 ] , Max { dp [ 1 ] …… dp [ i - 2 ] } + num [ i ] } ,最后输出 dp [ 100000 ] 即为答案。
AC:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll num[100005]; int main () { int n; scanf("%d", &n); memset(num, 0, sizeof(num)); for (int i = 0; i < n; ++i) { int ans; scanf("%d", &ans); num[ans] += (ll)ans; } ll Max = 0; Max = max(Max, num[1]); for (int i = 3; i <= 100000; ++i) { Max = max(num[i - 2], Max); num[i] = max(num[i] + Max, num[i - 1]); } printf("%I64d\n", num[100000]); return 0; }
相关推荐
"Boredom"这个标题可能指的是设计者试图通过字体来表达无聊或单调的情感,或者是在探索如何打破这种感觉的设计方法。下面我们将深入探讨字体设计的相关知识点: 1. **字体类型**:字体通常分为衬线、无衬线、手写体...
**Boredom Button-crx插件详解** Boredom Button是一款专为英语用户设计的浏览器扩展程序,旨在为用户在互联网上提供一种新颖且有趣的消遣方式。这款插件的核心功能是通过一键点击,随机展示各种类型的内容,包括...
"Get-Rid-Of-Boredom"这个项目可能是一个旨在利用JavaScript技术来提供娱乐或教育体验的项目,帮助用户克服无聊,或者可能是教用户如何利用JavaScript开发有趣的互动内容。 JavaScript的核心知识点包括: 1. **基础...
在"无聊模拟器"的源代码中(如boredom-simulator-master所示),我们可能会看到诸如HTML结构文件、CSS样式文件以及多个JavaScript文件。HTML定义了游戏界面的基本结构,CSS则负责样式和布局的设计。JavaScript文件...
在这个COVID-boredom-buster应用中,JavaScript将负责处理用户的交互,例如当用户点击获取随机活动的按钮时,JavaScript会生成并显示新的活动。此外,它还可能涉及到数据存储,比如利用浏览器的本地存储API保存用户...
==这到底是什么? == 我很无聊,所以我来看看并从网络友好的角度进行更改。 我主要是从Phaser教程开始的,它将从那里继续进行。 =到目前为止,我们得到了什么? =什么都没有== 01道奇游戏== 一个简单的游戏的快速而...
反乏味项目设置npm install编译和热重装以进行开发npm run serve编译并最小化生产npm run build运行单元测试npm run test:unit整理和修复文件npm run lint自定义配置请参阅。
一个简单,无聊的游戏,是作为“ Advertising”德国项目的一部分而创建的。 要进行下载,请在上方再按一下绿色的“下载”按钮
(中性/nertral、生气/anger、害怕/fear、高兴/joy、悲伤/sadness、厌恶/disgust、无聊/boredom),采样率48kHz(后压缩到16kHz),16bit量化,语料文本的选取遵从语义中性、无情感倾向的原则,且为日常口语化风格,无过多...
在简要介绍了文献中最重要的贡献之后,为了加深这个问题,我们使用以Boredom倾向量表BPS为主要工具从一项调查收集的数据(Farmer&Sundberg,1986),以确定可能的预防形式应在家庭,社会和机构背景下采用,以不...
17. 此题考察名词形式,“anxiety”的形容词形式是“anxious”,但题目中需要一个名词,即“boredom”。注意选项中的拼写错误,正确答案是C. boredom。 18. “lacking”在这里作形容词,表示“缺乏的”,修饰...
拯救我的哈哈用户故事: AS A user,I WANT to see gifs and jokes,SO THAT I alleviate my boredom.描述: 从用户选择的类别生成笑话和相关gif的应用程序。 笑话将通过JokeAPI数据库提供,gif将从giphy提供。 GIVEN ...
and other TV programs make you curious about our physical world -- or if you're a student forced to take a physics course -- now you can pursue the subject without the dread of boredom or the fear ...
and other TV programs make you curious about our physical world -- or if you're a student forced to take a physics course -- now you can pursue the subject without the dread of boredom or the fear ...
and other TV programs make you curious about our physical world -- or if you're a student forced to take a physics course -- now you can pursue the subject without the dread of boredom or the fear ...
and other TV programs make you curious about our physical world -- or if you're a student forced to take a physics course -- now you can pursue the subject without the dread of boredom or the fear ...
To enhance the interactive experience and reduce boredom, graphical dynamic display is applied, with black and white as the primary color scheme. Real-time adjustments of text font, size, and color ...