您的位置:首页 > 其它

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

#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-动态规划