CodeForces 467C George and Job
来源:互联网 发布:淘宝西班牙代购真假 编辑:程序博客网 时间:2024/05/29 15:24
*time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output*
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn’t have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of n integers p1, p2, …, pn. You are to choose k pairs of integers:
[l1, r1], [l2, r2], …, [lk, rk] (1 ≤ l1 ≤ r1 < l2 ≤ r2 < … < lk ≤ rk ≤ n; ri - li + 1 = m),
in such a way that the value of sum is maximal possible. Help George to cope with the task.
Input
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, …, pn (0 ≤ pi ≤ 109).
Output
Print an integer in a single line — the maximum possible value of sum.
Examples
input
5 2 1
1 2 3 4 5
output
9
input
7 1 3
2 10 7 18 5 33 0
output
61
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;#define INF 0x3f3f3f3f__int64 m,k,n,sum[10000],dp[5002][5002];void DP(){ int i,j; for(i=m;i<=n;i++) { for(j=1;j<=k;j++) { dp[i][j]=max(dp[i-m][j-1]+sum[i]-sum[i-m],dp[i-1][j]);//取当前长度为m的块和不取中选择最大的,当不取当前块的时候就需要从i-1块中取得满足条件最大的j块(当从i-1块中取的时候就不能再取当前的那块了) } } printf("%I64d\n",dp[n][k]);}int main(){ __int64 i,j,t,math[6000]; while(~scanf("%I64d%I64d%I64d",&n,&m,&k)) { sum[0]=0; for(i=1;i<=n;i++) { scanf("%I64d",&math[i]); sum[i]=sum[i-1]+math[i];//将前i个数值的和保存在当前sum中 } DP(); } return 0;}
- 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(动态规划)
- codeforces 467-C. George and Job(前缀和+dp)
- 一个通用链表模块(C语言)
- 用Eclipse开发安卓-无法正常预览布局文件layout.xml
- [leetcode] 107. Binary Tree Level Order Traversal II
- mysql不同字段类型所占用的空间
- ios7 statusbar透明设置
- CodeForces 467C George and Job
- 弹出广告视图
- 模板的特化
- 实习笔记4
- okhttp使用说明
- TTS授权失败 iOS百度导航
- hadoop错误各种原因
- (强推)内存泄漏与内存溢出分析解密
- vs2013 结合opencv3.0生成64位的动态链接库.dll