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 #include <algorithm>
10 #include <cmath>
11 using namespace std;
12
13 typedef long long ll;
14 const int MAXN = 5e3 + 10;
15 const int INF = 0x3f3f3f3f;
16 ll a[MAXN];
17 ll sum[MAXN];
18 ll dp[MAXN][MAXN];
19
20 int main(void)        //Codeforces Round #267 (Div. 2) C. George and Job
21 {
22     int n, m, k;
23     while (scanf ("%d%d%d", &n, &m, &k) == 3)
24     {
25         memset (sum, 0, sizeof (sum));
26         for (int i=1; i<=n; ++i)    {scanf ("%I64d", &a[i]);    sum[i] = sum[i-1] + a[i];}
27
28         ll ans = 0;
29         for (int i=m; i<=n; ++i)
30         {
31             ll tmp = sum[i] - sum[i-m];
32             for (int j=1; j<=k; ++j)
33             {
34                 dp[i][j] = max (dp[i-1][j], dp[i-m][j-1] + tmp);
35             }
36             ans = max (ans, dp[i][k]);
37         }
38
39         printf ("%I64d\n", ans);
40     }
41
42
43     return 0;
44 }
45
46 /*
47 5 2 1
48 1 2 3 4 5
49 7 1 3
50 2 10 7 18 5 33 0
51 */
时间: 2024-12-21 05:44:40

01背包 Codeforces Round #267 (Div. 2) C. George and Job的相关文章

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

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

wa哭了,,t哭了,,还是看了题解... 8170436                 2014-10-11 06:41:51     njczy2010     C - George and Job             GNU C++     Accepted 109 ms 196172 KB 8170430                 2014-10-11 06:39:47     njczy2010     C - George and Job             GNU C

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

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 #302 (Div. 2) C Writing Code

题目传送门 1 /* 2 题意:n个程序员,每个人每行写a[i]个bug,现在写m行,最多出现b个bug,问可能的方案有几个 3 完全背包:dp[i][j][k] 表示i个人,j行,k个bug dp[0][0][0] = 1 表示不选择人的时候所有的bug的种类犯错误都只有一种 4 dp[i][j][k] += dp[i%2][j-1][k-a[i]]: 5 错误示范:dp[i][j][k] += dp[i-1][j-l][k-l*a[i]]; 其实要从上一行的状态推出,即少一行 6 内存限制,

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

题目: 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