CF456C Boredom (DP)
CF#260 div2 C. Boredom
Codeforces Round #260
C. 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 Output
2 Input
3 Output
4 Input
9 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. |
题意:给出一堆数,一次操作是取某个数,然后等于(它+1)或(它-1)的数全删掉,得到(它)分,求最高得分。
有两种dp方法,一种排序后dp[i][j]表示取到第i个得到的最大分,j表示取或不取;
另一种是我用的,dp[i]表示在1~i的数中取,必取i,得到的最高分,从2扫到100000。
dp[i]=dp[i-];
if(a[i]>)dp[i]=max(dp[i],dp[i-]+1LL*i*a[i]);
注意10^5 * 10^5= 10^10会爆long long,我就是这样掉分飞起的。
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usint unsigned int
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout) const int maxn=;
int a[maxn];
ll dp[maxn]; int main(){
ll ma;
int n,i,x;
while(scanf("%d",&n)!=EOF){
mz(a);
for(i=;i<n;i++){
scanf("%d",&x);
a[x]++;
}
dp[]=;
dp[]=a[];
ma=dp[];
for(i=;i<=;i++)
{
dp[i]=dp[i-];
if(a[i]>)dp[i]=max(dp[i],dp[i-]+1LL*i*a[i]);
if(dp[i]>ma)ma=dp[i];
}
printf("%I64d\n",ma);
}
return ;
}
CF456C Boredom (DP)的更多相关文章
- 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 ...
- 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 455A Boredom (DP)
Boredom 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/G Description Alex doesn't like b ...
- 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 #260 DIV 2 C题Boredom(DP)
题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include & ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
随机推荐
- PHOG特征
PHOG特征 2016年7月13日 21:07:57 什么是PHOG PHOG是Pyramid HOG(pyramid histogram of oriented gradient)的简称,是在图像尺 ...
- 【poj2455】 Secret Milking Machine
http://poj.org/problem?id=2455 (题目链接) 题意 给出一张n个点,p条边的无向图,需要从1号节点走到n号节点一共T次,每条边只能经过1次,问T次经过的最大的边最小是多少 ...
- qibocms /hr/listperson.php File Arbitrarily Include Vul Via Variable Uninitialization && Front Page Upload WEBSHELL
catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 Relevant Link:2. 漏洞触发条件 . 找到前台文件上传点 ...
- Java文件处理:分离全国省市县ID(数据来自和风天气)
最近,在做第一行代码上的酷欧天气APP,但是发现书中的API已经用不了了,所以选择了和风天气的API,但是,在遍历省市县数据是遇到了麻烦,之前中国天气网是有个省市对应下一级行政区列表的,像这样: 但是 ...
- WCF入门
一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...
- VS2012旗舰版接选择调试 出现了这样一个错误
问题: 解决: 项目-右键-属性,勾选如下配置试试
- PMD(Put Me Down)用例测试
PMD(Put Me Down)--用例测试 一.测试工作安排 6个成员随机分配一个模块进行测试,测试完成后将最后的结果汇总到测试用例文档中. 二.测试工具的选择与运用 测试工具选择:这次还没用工具, ...
- C语言王国探秘一
我是一个WEB程序员,学习的是PHP.PHP是弱类型语言,学习的过程中,我能预见到以后技术进步的过程中,必然会遇到一些底层的东西.PHP的引擎Zend是C写的,PHP的很多扩展与插件是C写的.Linu ...
- HTML5学习总结-11 IOS 控件WebView显示网页
一 加载外部网页 1.使用UIWebView加载网页 运行XCode 新建一个Single View Application . 2 添加安全消息 添加以下消息到项目的 Info.plist &l ...
- 深入理解css中的margin属性
深入理解css中的margin属性 之前我一直认为margin属性是一个非常简单的属性,但是最近做项目时遇到了一些问题,才发现margin属性还是有一些“坑”的,下面我会介绍margin的基本知识以及 ...