Codeforces Round #267 (Div. 2) C
来源:互联网 发布:怎么把mac升级到10.11 编辑:程序博客网 时间:2024/06/06 14:26
题目:
C. George and Job
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputThe 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:
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.
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 ;}
0 0
- Codeforces Round #267 (Div. 2) C
- Codeforces Round #267 (Div. 2) C
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #267 (Div. 2)
- Codeforces Round #267 (Div. 2)
- Codeforces Round #267 (Div. 2)467B 467C
- Codeforces Round #267 (Div. 2) C. George and Job
- Codeforces Round #267 (Div. 2) C.George and Job
- Codeforces Round #267 (Div. 2) C. George and Job
- Codeforces Round #267 (Div. 2) C. George and Job
- Codeforces Round #267 (Div. 2) C. George and Job
- Codeforces Round #267 (Div. 2) C George and Job
- Codeforces Round #267 (Div. 2) A B C
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Codeforces Round #137 (Div. 2), problem: (C)
- Codeforces Round #153 (Div. 2) C题
- Codeforces Round #158 (Div. 2) C题
- linux 查看公网ip
- E: 无法获得锁 /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)解决方法
- Codeforces Round #267 (Div. 2) A
- Codeforces Round #267 (Div. 2) B
- c++ bit field
- Codeforces Round #267 (Div. 2) C
- 算法书籍推荐
- 有太多如同热度已投入的一天
- Stable Matching: Gale and Shapley Algorithm
- SQL Server Insert data into table
- 用javascript在对象中添加属性
- 第一次用阿里云ecs配置pptp vpn遇到的问题。
- f68;f86f7lfd865rf7l658
- struct 结构体的大小