CodeForces 467C George and Job
2016-07-18 10:12
183 查看
*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
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 [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; }
相关文章推荐
- dp---跳跃游戏
- 【DP】洛谷 P1541 乌龟棋
- 【DP】洛谷 P1510 精卫填海
- 【DP】洛谷 P1508 Likecloud-吃、吃、吃
- 【DP】洛谷 P1507 NASA的食物计划
- 【DP】洛谷 P1474 货币系统 Money Systems
- 【DP】洛谷 P1472 奶牛家谱 Cow Pedigrees
- 【DP】洛谷 P1470 最长前缀 Longest Prefix
- 【DP】洛谷 P1373 小a和uim之大逃离
- 【DP】洛谷 P1281 书的复制
- 【DP】洛谷 P1220 关路灯
- 【DP】洛谷 P1156 垃圾陷阱
- 【DP】洛谷 P1091 合唱队形
- 【DP】洛谷 P1063 能量项链
- 【DP】洛谷 P1064 金明的预算方案
- 【DP】洛谷 P1060 开心的金明
- 【DP】洛谷 P1020 导弹拦截
- 【DP】洛谷 P1018 乘积最大
- 【DP】洛谷 P1006 传纸条
- 【DP】洛谷 P1004 方格取数