Codeforces Round #260 (Div. 1) A - Boredom DP
A. Boredom
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/455/problem/A
Description
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));
代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-5
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** ll a[],dp[];
int main()
{
int n=read();
for(int i=;i<n;i++)
{
int x=read();
a[x]++;
}
for(int i=;i<;i++)
dp[i]=max(dp[i-],dp[i-]+a[i-]*(i-));
cout<<dp[]<<endl;
}
Codeforces Round #260 (Div. 1) A - Boredom DP的更多相关文章
- 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) ...
- 递推DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- 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 ...
- dp解Codeforces Round #260 (Div. 2)C. Boredom
#include<iostream> #include<map> #include<string> #include<cstring> #include ...
- 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 ...
- Codeforces Round #260 (Div. 1) Boredom(DP)
Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- 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 ...
- 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 ...
随机推荐
- elasticsearch-head 的搭建
elasticsearch-head 全部是js和html5写的,elasticsearch 全部都是http的接口, 这样,只需要简单地本地配置一个虚拟站点,就可以搭建 elasticsearch ...
- Ansible的条件语句
此篇主要讲述的ansible的condition,主要是用条件进行一些判断,此篇为官方文档的翻译,没有进行相关的测试,后续会写入相关的测试. Ansible的条件语句 1. 前言 在有的时候pl ...
- WebApi参数传递
c# webapi的参数传递方式:1.查询字符串(query string):2.内容主体(content body) 当然也有cookie或url部分或头部信息(header)等其它传方式,这里仅讨 ...
- 项目常用jquery/easyui函数小结
#项目常用jquery/easyui函数小结 ##背景 项目中经常需要使用到一些功能,封装.重构.整理后形成代码沉淀,在此进行分享 ##代码 ```javascript /** * @author g ...
- 老 base64 for xe8
not recommend ,only for study procedure TForm1.Button3Click(Sender: TObject); var ssi, sso: TStringS ...
- 【MySql】性能优化之分析命令
一 当发现程序运行比较慢的时候,首先排除物力资源问题之后,就将注意力转向mysq数据库: 1.首先确定运行慢的sql语句: mysql> show full processlist; 2.确认低 ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- C++拓扑排序
安利一篇比较写的比较好的的博客... 拓扑排序的原理及其实现 我本来以为我看懂了原理就会打了,没想到因为没有手动实践过...原理实际上也没记清楚.... 一题HDU的拓扑裸题HDU 3342 我的拓扑 ...
- 【转】删除已经存在的 TFS Workspace
删除已经存在的 TFS Workspace 分类: TFS2010-03-03 16:59 1239人阅读 评论(2) 收藏 举报 serverpathcommandcachefilegoogle 工 ...
- 修改Android 程序的icon快捷方式图标和名称
在res/drawable-hdpi或res/drawable-ldpi或res/drawable-mdpi目录下,加下你要显示的图片,最好后缀是为.png的,然后修改AndroidManifest. ...