Codeforces round #267 (Div. 2) c

Source: Internet
Author: User
Title: C. George and jobtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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 sequenceNIntegersP1 ,?P2 ,?...,?PN. You are to chooseKPairs of integers:

[ L1 ,? R1],? [ L2 ,? R2],?...,? [ L K,? R K] (1? ≤? L1? ≤? R1? <? L2? ≤? R2? <?...? <? L K? ≤? R K? ≤? N; R I? -? L I? +? 1? =? M),?

In such a way that the value of sum is maximal possible. Help George to interact with the task.

Input

The first line contains three IntegersN,MAndK(1? ≤? (M? ×?K)? ≤?N? ≤? (5000). The second line containsNIntegersP1 ,?P2 ,?...,?PN(0? ≤?PI? ≤? 109 ).

Output

Print an integer in a single line-the maximum possible value of sum.

Sample test (s) Input
5 2 11 2 3 4 5
Output
9
Input
7 1 32 10 7 18 5 33 0
Output
61

Question Analysis: DP. DP [I] [J] before saving I has the maximum value of group J.
State transition equation:
if(i-m>=0)dp[i][j] = max(dp[i][j],max(dp[i-1][j],dp[i-m][j-1]+b[i]-b[i-m])) ;
else 
<span style="white-space:pre"></span>dp[i][j] = max(dp[i][j],dp[i-1][j]) ;
B [I] saves the sum of I items A [I.
Code:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;long long dp[5005][5005] ;long long a[65555] ;long long b[65555] ;int main(){int n,m,k ;cin>>n>>m>>k;int i,j;for(i=1;i<=n;i++){cin>>a[i];b[i] = b[i-1] + a[i] ;}for(i=1;i<=n;i++){for(j=1;j<=k;j++){if(i-m>=0)dp[i][j] = max(dp[i][j],max(dp[i-1][j],dp[i-m][j-1]+b[i]-b[i-m])) ;else dp[i][j] = max(dp[i][j],dp[i-1][j]) ;}}cout<<dp[n][k]<<endl;return 0 ;}



Codeforces round #267 (Div. 2) c

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.