C. George and Job
来源:互联网 发布:机房网络同传软件 编辑:程序博客网 时间:2024/06/05 17:28
题目链接:
http://codeforces.com/contest/467/problem/C
· 二维DP
· 题目中其实也有一个特点数字: 5000, 预示着可能使用二维dp。int f[5050][5050]可以开下,但是int f[10010][10010] 有的OJ就不行了
· 注意结果会超int 。
dp[i][j]表示在取到第i个元素的时候取j个m长度的区间之和的最大值。
dp[i][j]可由dp[i-1][j]不添加区间得到的,或者由dp[i-m][j-1]添加一个区间得到。
遂有状态转移方程:dp[i][j]=max(dp[i-1][j],dp[i-m][j-1]+s[i]-s[i-m]),(其中s是前缀和。)
AC Code:
1 #include <iostream> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 #include <queue> 6 using namespace std; 7 #define LL long long 8 #define N 5050 9 int deal(int i){10 11 12 }13 LL f[N],sum[N],dp[N][N];14 int main(){15 freopen("in.txt","r",stdin);16 //freopen("out.txt","w",stdout);17 //状态转移方程: dp[i][j] = dp[i-1][j] / dp[i-m][j-1] + sum[i]-sum[i-m];18 int n,m,k;19 while(cin>>n>>m>>k){20 for(int i=1;i<=n;i++) scanf("%d",&f[i]);21 LL num=0;22 for(int i=1;i<=n;i++){23 num += f[i]; sum[i] = num; //前缀和24 }25 //printf(" sum : %d -- m :%d\n",num,m);26 memset(dp,0,sizeof(dp));27 for(int i=1;i<=n;i++){28 for(int j=1;j<=k;j++){29 //前i个数字,取j段 m 长的数字;30 if(i-m>=0)31 dp[i][j] = max(dp[i-1][j],dp[i-m][j-1]+sum[i]-sum[i-m]);32 }33 }34 printf("%lld\n",dp[n][k]);35 }36 37 38 return 0;39 }
0 0
- C. George and Job
- 【CODEFORCES】 C. George and Job
- Codeforces 467C. George and Job
- 【DP】 467C George and Job
- Codeforces 467C George and Job
- codeforces 467C George and Job dp
- 【CF】 467C George and Job DP
- CF 267C George and Job
- Codeforces 467C George and Job(dp)
- codeforces 467C - George and Job
- codefores #267C George and Job(dp)
- CF 467C DP George and Job
- Codeforces 467 C. George and Job
- Codeforces 467C George and Job(dp)
- Codeforces 467C George and Job(dp)
- codeforces-467C-George and Job【dp】
- CodeForces - 467C George and Job
- Codeforce 467C. George and Job(DP)
- 虚拟目录配置
- 虚拟主机配置方案(二)通过ServerName端,来区分不同的域名
- 西安赛区网络赛
- Android 4.1打开相机(自己写的压力测试APK)
- 博弈问题及SG函数
- C. George and Job
- Java编码规范(转)
- html弹框效果(移动Web)
- jsp与servlet中文乱码问题(转)
- 霍夫曼树计算 WPL
- 二分图最佳匹配
- sql server 中 SET 与 SELECT 赋值区别
- GROUP BY分组查询中问题
- C. MUH and House of Cards (题目类型很有特点,存一下以便学习)