A. Boredom

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/455/problem/A

Description

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 Input

2
1 2

Sample Output

2

HINT

题意

给你n个数,你每次可以选择删除去一个数x,但是等于x+1和等于x-1的数都得删去

你每一次操作可以得x分

题解:

dp,dp[i]表示到i后能够得到的最大分数

dp[i]=max(dp[i-1],dp[i-2]+a[i-1]*(i-1));

代码:

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <set>
  8. #include <vector>
  9. #include <sstream>
  10. #include <queue>
  11. #include <typeinfo>
  12. #include <fstream>
  13. #include <map>
  14. #include <stack>
  15. typedef long long ll;
  16. using namespace std;
  17. //freopen("D.in","r",stdin);
  18. //freopen("D.out","w",stdout);
  19. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  20. #define test freopen("test.txt","r",stdin)
  21. #define maxn 2000001
  22. #define mod 10007
  23. #define eps 1e-5
  24. const int inf=0x3f3f3f3f;
  25. const ll infll = 0x3f3f3f3f3f3f3f3fLL;
  26. inline ll read()
  27. {
  28. ll x=,f=;char ch=getchar();
  29. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  30. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  31. return x*f;
  32. }
  33. //**************************************************************************************
  34.  
  35. ll a[],dp[];
  36. int main()
  37. {
  38. int n=read();
  39. for(int i=;i<n;i++)
  40. {
  41. int x=read();
  42. a[x]++;
  43. }
  44. for(int i=;i<;i++)
  45. dp[i]=max(dp[i-],dp[i-]+a[i-]*(i-));
  46. cout<<dp[]<<endl;
  47. }

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

  1. DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) ...

  2. 递推DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...

  3. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  4. Codeforces Round #260 (Div. 2)C. Boredom(dp)

    C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. dp解Codeforces Round #260 (Div. 2)C. Boredom

    #include<iostream> #include<map> #include<string> #include<cstring> #include ...

  6. Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)

    题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory l ...

  7. Codeforces Round #260 (Div. 1) Boredom(DP)

    Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  8. Codeforces Round #260 (Div. 2) A B C 水 找规律(大数对小数取模) dp

    A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. Codeforces Round #260 (Div. 2) A , B , C 标记,找规律 , dp

    A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

随机推荐

  1. Java并发编程-总纲

    Java 原生支持并发,基本的底层同步包括:synchronized,用来标示一个方法(普通,静态)或者一个块需要同步执行(某一时刻,只允许一个线程在执行代码块).volatile,用来标识一个变量是 ...

  2. win 7 下Maven环境的搭建

    Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具. Maven是什么? 比较正式的定义:Maven是一个项目管理工具,它包含了: 一个项目对象模型 (Project O ...

  3. Drupal如何SQL查询传递参数?

    Drupal使用称之为“placeholder”的方式处理SQL查询参数: <?php // WRONG: $result = db_query("SELECT nid, title ...

  4. 基于opencv的人脸检测的web应用

    参考资料 https://github.com/bsdnoobz/web-based-face-detect http://opencv-code.com/projects/web-based-int ...

  5. SpringMVC 3.1集成Spring Security 3.1

    这篇算是一个入门文章,昨天看见有网友提问,spring mvc集成spring security 的时候出错,揣测了一下问题木有解决.我就帮忙给搭建了一个集成框架他说可以,他告诉我这样的文章网上少.今 ...

  6. Cocos2d-android (04) 执行多个动作

    先后.同时执行多个动作及动作序列执行结束后的事件 import org.cocos2d.actions.instant.CCCallFunc; import org.cocos2d.actions.i ...

  7. Connection failed: NT_STATUS_ACCOUNT_RESTRICTION

    今天在linux机器上想要远程重启一台window的机器,输入命令后报错,如下 Google了下,有说是window禁止远程空密码登录,于是到window系统中添加了密码,这下再运行 这下执行就正常了

  8. Linux_系统信息

    公司里一些仿真软件得进Linux系统,好奇公司用的什么Linux版本,于是搜罗了几个命令如下: 1  uname - Print system info -a, print all info -s, ...

  9. Linux下的GitHub安装与简单配置教程

    1.GitHub简介 Git是一个分布式版本控制系统,与其相对的是CVS.SVN等集中式的版本控制系统. 2.Git的安装 1)安装Git a.查看与使用 在ubuntu下可以使用如下命令进行查看系统 ...

  10. UNIX环境下用C语言写静态库与动态库

    静态库,动态库用UNIX 的术语来说,或者叫做归档文件(archive 常以.a 结尾)和共享对象(share object 常以lib 开头.so 结尾)更为准确.静态库,动态库可能是WINDOWS ...