Codeforces 467C George and Job(dp)
2014-09-26 20:14
363 查看
题目链接:Codeforces 467 George and Job
题目大意:给定一个长度为n的序列,从序列中选出k个不重叠且连续的m个数,要求和最大。
解题思路:dp[i][j]表示到第i个位置选了j个子序列。
题目大意:给定一个长度为n的序列,从序列中选出k个不重叠且连续的m个数,要求和最大。
解题思路:dp[i][j]表示到第i个位置选了j个子序列。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const int maxn = 5005; int N, M, K; ll arr[maxn], sum[maxn]; ll dp[maxn][maxn]; ll solve () { ll ret = 0; for (int i = M; i <= N; i++) { ll tmp = sum[i] - sum[i-M]; for (int j = 1; j <= K; j++) dp[i][j] = max(dp[i-1][j], dp[i-M][j-1] + tmp); ret = max(ret, dp[i][K]); } return ret; } int main () { scanf("%d%d%d", &N, &M, &K); for (int i = 1; i <= N; i++) { scanf("%lld", &arr[i]); sum[i] = sum[i-1] + arr[i]; } printf("%lld\n", solve()); return 0; }
相关文章推荐
- codeforces 467C George and Job(简单dp,看了题解抄一遍)
- codeforces 467C George and Job dp
- Codeforces 467C George and Job DP
- Codeforces 467C George and Job(dp)
- Codeforces 467C George and Job(dp)
- Codeforces 467C George and Job(dp)
- Codeforces 467C George and Job(DP)
- codeforces 467C George and Job dp
- CodeForces - 467C George and Job
- Codeforces 467C. George and Job
- 【CF】 467C George and Job DP
- 【CF】 467C George and Job DP
- Codeforces 467C George and Job(动态规划)
- codeforces 467CGeorge and Job
- Codeforces Round #267 (Div. 2)467C George and Job(dp)
- cf_467C_George and Job
- codeforces-467C-George and Job【dp】
- Codeforces 467C. George and Job (dp)
- Codeforces Round #267 (Div. 2) C. George and Job DP
- [CodeForces 467C]George and Job[DP]