codeforces 467CGeorge and Job
来源:互联网 发布:bilibili mac电脑直播 编辑:程序博客网 时间:2024/05/15 19:42
dp[i][j]: 前 i 个数中,选择 j pairs 可以获得的最大和。
sum[i] = a[1] + a[2] + .....+a[i];
那么对于第 i 个数来说,有不选和选择的两种情况。
1.如果不选第 i 这个数 ,即dp[i-1][j],表示前 i 个数,选择 j pairs 获得的最大和 = 前i-1个数中选择 j pairs 可以获得的最大和;
2.如果选第 i 个数,状态就转移到 dp[i-m][j-1] + sum[i] - sum[i-m],这个 sum[i]- sum[i-m] 会成为新的一个pair,前面那个第 i-m 个数就不要选。
/**************************************************************** *Author:fisty *Data:2014-10-12 *codeforces 467C *DP dp[i][j] = max(dp[i-1][j] , dp[i-m][j-1] + sum[i] - sum[i-m] ); *****************************************************************/#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define MAX_N 5050int n,m,k;// 0 <= p <= 10^9long long sum[MAX_N];long long dp[MAX_N][MAX_N]; int main(){ //freopen("in", "r", stdin); while(scanf("%d%d%d", &n, &m, &k) != EOF){ memset(dp, 0LL, sizeof(dp)); sum[0] = 0; int t; for(int i = 1;i <= n; i++){ scanf("%d", &t); sum[i] = sum[i-1] + t; } for(int i = m;i <= n ; i++){ for(int j = 1; j<=k && j<=i/m; j++){ dp[i][j] = max(dp[i-1][j], dp[i-m][j-1] + sum[i] - sum[i-m]); } } printf("%I64d\n", dp[n][k]); } return 0;}
0 0
- codeforces 467CGeorge and Job
- Codeforces 467C. George and Job
- Codeforces 467C George and Job
- codeforces 467C George and Job dp
- Codeforces 467C George and Job(dp)
- codeforces 467C - George and Job
- Codeforces 467 C. George and Job
- Codeforces 467C George and Job(dp)
- Codeforces 467C George and Job(dp)
- codeforces-467C-George and Job【dp】
- CodeForces - 467C George and Job
- [CodeForces 467C]George and Job[DP]
- CodeForces 467C George and Job
- Codeforces 467C George and Job DP
- Codeforces 467C George and Job(dp)
- 【CODEFORCES】 C. George and Job
- Codeforces 467C George and Job【dp】好题~
- Codeforces 467C George and Job(动态规划)
- iap包的提交
- 使用 DrMemory 发现内存编程错误
- 走爪坐撞嘴灼诅缀庄钻揍灼坠坠椎孜灼醉
- ZOJ 3805 Machine
- 拽抓祖爪紫庄啄渍注揍祖紫缀左浊专赘锥
- codeforces 467CGeorge and Job
- 抓座做邹祖转坐诅坠资总纵作自驻宗驻总
- placeholder
- Eclipse安装WindowBuilder
- 第一次写博客
- 头文件的包含以及命名空间的引入尽量写在cpp里
- .net CHARTING图表控件下载地址
- POJ LAKE COUNTING 2386
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 H,字符串模拟)