codeforces George and Job

 1 /*
 2     题意:给一个长度为n的序列, 从中选择长度为m的k个区间(任意两个区间不会有公共部分)
 3     使得所选择的区间的和最大!
 4     思路:这是一种很常见的dp
 5
 6     dp[i][j] 表示的是前 i 个数选择 j 个 长度为m区间的最大和!
 7     s[i]记录的是前 i 个数字的和!
 8     dp[i][j] = max( dp[i - 1][j], dp[i - m][j - 1] + s[i] - s[i-m] );
 9 */
10 #include<iostream>
11 #include<cstdio>
12 #include<cstring>
13 #include<algorithm>
14 #define N 5005
15 using namespace std;
16 typedef long long ll;
17
18 ll dp[N][N];
19 ll s[N];
20
21 int main(){
22     int n, m, k;
23     scanf("%d%d%d", &n, &m, &k);
24     for(int i = 1; i <= n; ++i){
25         scanf("%lld", &s[i]);
26         s[i] += s[i-1];
27     }
28
29     for(int j = 1; j <= k; ++j)
30         for(int i = j*m; i <= n; ++i)
31            dp[i][j] = max( dp[i - 1][j], dp[i - m][j - 1] + s[i] - s[i-m] );
32
33     printf("%lld\n", dp[n][k]);
34
35     return 0;
36 }
时间: 2024-10-13 12:42:38

codeforces 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

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 #227 (Div. 2)---E. George and Cards(贪心, 树状数组+set维护, 好题!)

George is a cat, so he loves playing very much. Vitaly put n cards in a row in front of George. Each card has one integer written on it. All cards had distinct numbers written on them. Let's number the cards from the left to the right with integers f

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) 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 387E George and Cards

George and Cards 我们找到每个要被删的数字左边和右边第一个比它小的没被删的数字的位置.然后从小到大枚举要被删的数, 求答案. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pa

Codeforces Round #227 (Div. 2) / 387C George and Number (贪心)

链接:here~~~ 分割最多的数,使得分割的数连接在一起,得到原来的数,(分割的数大的放前面,两个数合并 比较此数大于后面的数,否则合并成一个数,不能分割,0不能单独存在) #include<iostream> using namespace std; int main() { string s; int i , j , ans = 0; cin >> s; for( i = 0; s[i] ;i = j) { for(j = i + 1 ; s[j] == '0';j ++);

Codeforces 467C George and Job(dp)

求k个不覆盖的最大连续区间和,每个区间长度为m. 影响决策的因素有k和区间和,所以dp[i][j]的含义就显而易见了,表示在以第i个数的位置选择了j个子序列的最大值. 那么根据递推关系不难写出递推表达式dp[i][j] = max(dp[i-1][j],dp[i-m][j-1]+sum[i]);其中dp[i-1][j]的作用值得我们细细品味,它的作用是将状态转移过来. 而且因为区间的不覆盖性,我们要先枚举位置,再枚举子序列的个数. #include<cstdio> #include<cs