题目链接: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. 架构-Eureka:第一个方法

    ylbtech-架构-Eureka:第一个方法 工程介绍 Spring Cloud 工程目录 model registry-center Servers tzxyfx tzxyfx-provider ...

  2. python print 显示不同的字体

    显示格式: print('\033[显示方式;字体颜色;背景色m.....\033[0m') ------------------------------- 显示方式 | 效果 ----------- ...

  3. C# net winform wpf 发送post数据和xml到网页

    由于项目需要发送数据到网页 这里用aspx做测试 采用post以及get发送数据,页面进行数据  首先这个东西很简单很简单,基本上学过的都会,但是原谅一直搞cs几乎不搞bs的猿类吧.三四年没接触bs. ...

  4. Super超级ERP系统---(6)采购管理--入库上架

    采购商品入库完成后,下一步就是上架操作.所谓上架就是把入库放到移动托盘的商品转移到固定货架上,货架上有货位号,可以把商品放到指定的货位上.主要分两步操作,上架操作主要是移动PDA上完成的  1.扫描移 ...

  5. Three.js入门——画星空(star field)

    Three.js是一个很流行的3D JavaScript库.这里有一个three.js的入门教程,在浏览器窗口中画出星空.我按照教程重新实现了一遍,这里的这篇博客把教程大致翻译了一遍.我的demo. ...

  6. USB接口大全

    USB2.0系列: Standard A: Standard B: Mini Standard B: Micro USB: ** Micro USB 与 Mini B比较 ** USB3.0系列: U ...

  7. 开源作品-PHP写的JS和CSS文件压缩利器(单文件绿色版)-SuMinify_PHP_1_5

    前言: 网站项目需要引用外部文件以减小加载流量,而且第一次加载外部资源文件后,其他同域名的页面如果引用相同的地址,可以利用浏览器缓存直接读取本地缓存资源文件,而不需要每个页面都下载相同的外部资源文件. ...

  8. 决策树构建算法之—C4.5

    这个网站值得收藏一下,原文链接:http://shiyanjun.cn/archives/428.html 决策树算法的优越性在于:离散学习算法进行组合总可以表达任意复杂的布尔函数,并不受数据集的限制 ...

  9. 应运而生! 双11当天处理数据5PB—HiStore助力打造全球最大列存储数据库

    阿里巴巴电商业务中历史数据存储与查询相关业务, 大量采用基于列存储技术的HiStore数据库,双11当天HiStore引擎处理数据记录超过6万亿条.原始存储数据量超过5PB.从单日数据处理量上看,该系 ...

  10. JS 作业

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...