Codeforces Round #267 (Div. 2) C

题目:

C. George and Job

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?≤?nri?-?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 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 1
1 2 3 4 5

output

9

input

7 1 3
2 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 ;
}

时间: 2024-08-26 00:31:04

Codeforces Round #267 (Div. 2) C的相关文章

Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ 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 follow

01背包 Codeforces Round #267 (Div. 2) C. George and Job

题目传送门 1 /* 2 题意:选择k个m长的区间,使得总和最大 3 01背包:dp[i][j] 表示在i的位置选或不选[i-m+1, i]这个区间,当它是第j个区间. 4 01背包思想,状态转移方程:dp[i][j] = max (dp[i-1][j], dp[i-m][j-1] + sum[i] - sum[i-m]); 5 在两个for循环,每一次dp[i][j]的值都要更新 6 */ 7 #include <cstdio> 8 #include <cstring> 9 #i

Codeforces Round #267 (Div. 2) C. George and Job

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 p

Codeforces Round #267 (Div. 2)

A.George and Accommodation 题意:给定数组a,b,问b-a>=2有多少个 思路:直接模拟.. B.Fedor and New Game 题意:给定m+1个n位以内的二进制数,求前m个有多少个跟第m+1的二进制下不同位数不超过k的个数 思路:直接模拟 C.George and Job 题意:给定n个数,求k个的段,每段有m个连续得数,使得和最大 思路:直接dp,注意long long不会超内存 1 /* 2 * Author: Yzcstc 3 * Created Tim

Codeforces Round #267 (Div. 2) B. Fedor and New Game

After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game ?Call of Soldiers 3?. The game has (m?+?1) players and n types of soldiers in total. Players ?Call of Soldiers 3? are numbered for

Codeforces Round #267 (Div. 2) 水了一发 真.记录

闲着没事就水了一发DIV2,本来想新注册一个小小号来着.结果验证码一直显示不出来.于是就用小号做. 结果rank44,但是没有rating. 以下均不解释题意了. A:O(n)脑残模拟. Code: #include <cstdio> int main() { int n, a, b; scanf("%d", &n); int res = 0; while(n--) { scanf("%d%d", &a, &b); if (a +

Codeforces Round #267 (Div. 2) A. George and Accommodation

George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory ha

Codeforces Round #267 (Div. 2) A

题目: A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Al

Codeforces Round #267 (Div. 2) B

题目: B. Fedor and New Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer