Codeforces Round #267 (Div. 2) C

來源:互聯網
上載者:User

標籤:演算法   acm   codeforces   algorithm   hdu   

題目: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 sequence of n integers p1,?p2,?...,?pn. You are to choose k pairs of integers:

[ l1,? r1],?[ l2,? r2],?...,?[ l k,? r k] (1?≤? l1?≤? r1?<? l2?≤? r2?<?...?<? l k?≤? r k?≤? nr i?-? l i?+?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 nm 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.

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

題意分析:DP一下。dp[I][j]存前i有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 
<span style="white-space:pre"></span>dp[i][j] = max(dp[i][j],dp[i-1][j]) ;
其中b[i]存前i項a[i]的和。
代碼:
#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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.