题目链接:http://codeforces.com/problemset/problem/455/A

A. Boredom
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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).

Output

Print a single integer — the maximum number of points that Alex can earn.

Sample test(s)
input
2
1 2
output
2
input
3
1 2 3
output
4
input
9
1 2 1 3 2 2 2 2 3
output
10
Note

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.

题意:

给定一个序列。每次从序列中选出一个数ak,获得ak的得分。同一时候删除序列中全部的ak−1,ak+1,

求最大得分的值。

思路:

存下每一个数的个数放在c中。消除一个数i,会获得c[i]*i的值(由于能够消除c[i]次),

假设从0的位置開始向右消去,那么。消除数i时。i-1可能选择了消除。也可能没有,

假设消除了i-1,那么i值就已经不存在,dp[i] = dp[i-1]。

假设没有被消除,那么dp[i] = dp[i-2]+ c[i]*i。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL __int64
const int MAXN = 100017;
LL c[MAXN], dp[MAXN];
void init()
{
memset(dp,0,sizeof(dp));
memset(c,0,sizeof(c));
}
int main()
{
LL n;
LL tt;
int i, j;
while(~scanf("%I64d",&n))
{
init();
int maxx = 0;
for(i = 1; i <= n; i++)
{
scanf("%I64d",&tt);
if(tt > maxx)
maxx = tt;
c[tt]++;
}
dp[0] = 0, dp[1] = c[1];
for(i = 2; i <= maxx; i++)
{
dp[i] = max(dp[i-1],dp[i-2]+c[i]*i);
}
printf("%I64d\n",dp[maxx]);
}
return 0;
}

Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)的更多相关文章

  1. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  2. codeforces #260 DIV 2 C题Boredom(DP)

    题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include & ...

  3. Codeforces Round #369 (Div. 2) C. Coloring Trees(dp)

    Coloring Trees Problem Description: ZS the Coder and Chris the Baboon has arrived at Udayland! They ...

  4. Codeforces Round #245 (Div. 1) B. Working out (dp)

    题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...

  5. Codeforces Round #349 (Div. 2) C. Reberland Linguistics (DP)

    C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. Codeforces Round #369 (Div. 2) C. Coloring Trees (DP)

    C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)

    题目链接 大意:给你n个物品和m种优惠方式,让你买k种,问最少多少钱. 思路:考虑dpdpdp,dp[x]dp[x]dp[x]表示买xxx种物品的最少花费,然后遍历mmm种优惠方式就行转移就好了. # ...

  8. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  9. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

随机推荐

  1. 南海区行政审批管理系统接口规范v0.3(规划) 5.投资项目联合审批系统API 5.1.【uploadFile】证件文书附件上传

  2. shp系列(五)——利用C++进行shp文件的写(创建)

    之前介绍了shp文件.dbf文件和shx文件的的读取,接下来将分别介绍它们的创建过程.一般来说,读和写的一一对应的,写出的文件就是为了保存数据供以后读取的.写的文件要符合shapefile的标准.之前 ...

  3. 使用Micrisoft.net设计方案 第三章Web表示模式

    第三章Web表示模式 体系结构设计者在设计第一个作品时比较精简和干练.在第一次设计时,并清除自己做什么,因此比较小心谨慎.第二个作品是最危险的一个作品,此时他会对第一个作品做修饰和润色,以及把第一次设 ...

  4. Codeforces Round #446

    Greed #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector&g ...

  5. JavaScript的switch循环

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  6. Java I/O streams

    I/O Streams Byte Streams 输入输出以字节为单位,所有的使用字节流的类都继承自 InputStream 和 OutputStream. Byte Streams 属于 low-l ...

  7. 在AndroidManifest(清单文件)中注册activity(活动)及配置主活动、更改App图标、App名称、修改隐藏标题栏

    打开app/src/main/AndroidManifest. <?xml version="1.0" encoding="utf-8"?> < ...

  8. 极光推送设置标签和别名无效的解决办法:JPush设置别名不走成功回调

    极光推送设置标签和别名无效的解决办法 JPush设置别名不走成功回调的解决办法 http://www.cnblogs.com/chenqitao/p/5506023.html 主要是网络加载过快导致的 ...

  9. SQL 字段类型详解

    bit    整型 bit数据类型是整型,其值只能是0.1或空值.这种数据类型用于存储只有两种可能值的数据,如Yes 或No.True 或False .On 或Off.    注意:很省空间的一种数据 ...

  10. 在线场景感知:图像稀疏表示—ScSPM和LLC总结(以及lasso族、岭回归)

    前言: 场景感知其实不分三维场景和二维场景,可以使用通用的方法,不同之处在于数据的形式,以及导致前期特征提取及后期在线场景分割过程.场景感知即是场景语义分析问题,即分析场景中物体的特征组合与相应场景的 ...