Codeforces Round #260 (Div. 2) C Boredom
来源:互联网 发布:淘宝卖家帐号被冻结 编辑:程序博客网 时间:2024/05/22 09:49
比赛当中用了错误方法没搞出来,比赛结束后学长提醒是简单DP。-两分钟迅速推出状态转移方程是 dp[i]=max(dp[i-1],dp[i-2]+a[i]),然后...被学长说这个是不行的- -
说是我这个状态不能直接由上一个状态转移过来...但自己感觉是没错的-然后今早试了试没错,果断AC.
#include<stdio.h>#include<string.h>__int64 dp[100005],a[100005];__int64 max(__int64 x,__int64 y){ if(x<y) return y; return x;}int main(){ int n,i,x; scanf("%d",&n); memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); for(i=0;i<n;i++) { scanf("%d",&x); a[x]+=x; } for(i=1;i<=100000;i++) dp[i]=max(dp[i-2]+a[i],dp[i-1]); printf("%I64d\n",dp[100000]); return 0;}附上学长写的:
#include<stdio.h>#include<string.h>const int N=100005;typedef long long LL;LL a[N];LL dp[N][2];LL Max(LL x,LL y){ if(x>y) return x; else return y;}int main(){ int n; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) { LL x; scanf("%I64d",&x); a[x]+=x; } memset(dp,0,sizeof(dp)); for(int i=1;i<=100000;i++) { dp[i][0]=Max(dp[i-1][0],dp[i-1][1]); dp[i][1]=dp[i-1][0]+a[i]; } printf("%I64d\n",Max(dp[100000][0],dp[100000][1])); } return 0;}
0 0
- Codeforces Round #260 (Div. 2) C. Boredom
- Codeforces Round #260 (Div. 2) C Boredom
- Codeforces Round #260 (Div. 2)C. Boredom
- Codeforces Round #260 (Div. 2)C. Boredom(dp)
- Codeforces Round #260 (Div. 2) C. Boredom【DP】
- dp解Codeforces Round #260 (Div. 2)C. Boredom
- Codeforces Round #260 (Div. 2)——C. Boredom
- Codeforces Round #260 (Div. 2) C. Boredom(DP)
- Boredom - CodeForces #260 (Div. 2) C dp
- Codeforces Round #260 (Div. 2)455A - Boredom (DP)
- Codeforces Round #260 (Div. 1) A. Boredom
- Codeforces Round #260 (Div. 1) A. Boredom
- Codeforces Round #260 (Div. 1) A. Boredom
- Codeforces Round #433 (Div. 2) E. Boredom
- codeforces #260 DIV 2 C题Boredom(DP)
- Codeforces #260 (Div. 2) C. Boredom(动态规划)
- Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)
- Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)
- ORACLE里边的单行函数
- ECSHOP购物流程收货人信息详细地址显示省市区
- Wikioi-1069 关押罪犯
- 鬼探推理大赛
- Linux驱动学习——等待队列
- Codeforces Round #260 (Div. 2) C Boredom
- Surprising Strings
- hdu2795Billboard(线段树,找第一个大于w的点)
- JSON.parse()和JSON.stringify()
- JS之Promise思维模式
- 我的博客时代
- opencv2.2 交叉编译 及在arm开发板测试
- 编译器没有报错,但是部署项目不成功的解决方案
- 全面探索 FreeMarker 模版引擎的扩展性