日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 467C】George and Job(dp,思维)

發(fā)布時(shí)間:2023/12/10 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 467C】George and Job(dp,思维) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

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

題目大意:

? 給定n,m,k。求k個(gè)子段,每一段的長度是m,且每一段均要求不相交。求選中段的最大和。

解題報(bào)告:

直接dp[i][j]代表前i個(gè)數(shù),分成j個(gè)子段,的最大和,然后轉(zhuǎn)移即可。

也可以定義成dp[i][j]代表以第i個(gè)數(shù)為結(jié)尾,分成j個(gè)子段的最大和,這樣的話需要枚舉上一個(gè)斷點(diǎn),不過可以用一個(gè)數(shù)組預(yù)處理前綴最大值,所以復(fù)雜度是一樣的,都可解。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; ll a[MAX],sum[MAX],dp[5005][5005],n,m,k; int main() {cin>>n>>m>>k;for(int i = 1; i<=n; i++) scanf("%lld",a+i);for(int i = 1; i<=n; i++) sum[i] = sum[i-1] + a[i];for(int i = m; i<=n; i++) {for(int j = 1; j<=k; j++) {dp[i][j] = max(dp[i-1][j],dp[i-m][j-1] + sum[i]-sum[i-m]);}}printf("%lld\n",dp[n][k]);return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【CodeForces - 467C】George and Job(dp,思维)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。