Codeforces 467C (dp,prefix sum)
2017-03-28 16:41
399 查看
预处理,求出prefix_sum[]前缀和数组
然后二维dp,转移方程:
然后二维dp,转移方程:
dp[i][j] = max(dp[i][j-1],dp[i-1][j-m]+prefix_sum[j]-prefix_sum[j-m]);
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define maxn 5010 long long prefix_sum[maxn]; long long dp[maxn][maxn]; int main() { memset(prefix_sum,0,sizeof(prefix_sum)); memset(dp,0,sizeof(dp)); long long n,m,k; scanf("%I64d%I64d%I64d",&n,&m,&k); scanf("%I64d",&prefix_sum[1]); for(int i=2;i<=n;i++) { 4000 scanf("%I64d",&prefix_sum[i]); prefix_sum[i]+=prefix_sum[i-1]; } for(int i=1;i<=k;i++) { for(int j=m;j<=n;j++) { dp[i][j] = max(dp[i][j-1],dp[i-1][j-m]+prefix_sum[j]-prefix_sum[j-m]); } } printf("%I64d\n",dp[k] ); return 0; }
相关文章推荐
- codeforces 467C George and Job dp
- CodeForces 467C DP
- Codeforces 126D Fibonacci Sums 求n由任意的Sum(fib)的方法数 dp
- codeforces 285 D Permutation Sum (状态压缩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 577 B Modulo Sum 简单数学+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 895A (入门 prefix sum)
- codeforces 467C George and Job(简单dp,看了题解抄一遍)
- Codeforces 489E Hiking(普通01分数规划加DP)
- codeforces 339C Xenia and Weights(dp或暴搜)
- Codeforces_484D:Kindergarten(贪心/DP)