CF 467C DP George and Job
来源:互联网 发布:中标软件 编辑:程序博客网 时间:2024/06/15 14:06
转移方程
d[i+1] [j] = s[j+m-1] - s[j-1] + max ( d[i] [x]), (1<=x<=j-m)
d[i] [j] 表示第i个区间以第j个数开始的最大值。
另外后面求最大值有个优化方法,因为每一次j总增加1,也就是x只增加1个值,所以只需把当前的和最大值比较就可以了。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <vector>#include<map>#define pi acos(-1.0)#define eps 1e-6#define inf 1<<30#define INF 1ll<<60#define ll long long#define MOD 1000000007using namespace std;int a[5010];ll d[5010][5010];ll s[5010];int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=1; i<=n; i++) scanf("%d",&a[i]); s[0]=0; s[1]=a[1]; for(int i=2; i<=n; i++) s[i]=s[i-1]+a[i]; for(int i=1; i+m-1+(k-1)*m<=n; i++) d[1][i]=s[i+m-1]-s[i-1]; for(int i=1; i<=k-1; i++) { ll Max=0; for(int j=1; j<=n; j++) {// for(int p=1; p+m<=j; p++)// {// Max=max(Max,d[i][p]);// } if(j-m>=1) //优化方法 Max=max(Max,d[i][j-m]); else Max=0; d[i+1][j]=Max+s[j+m-1]-s[j-1]; } } ll ans=0; for(int i=1; i<=n; i++) ans=max(ans,d[k][i]); printf("%I64d\n",ans); return 0;}
0 0
- 【CF】 467C George and Job DP
- CF 467C DP George and Job
- CF 467C - George and Job (简单区间DP)
- 【DP】 467C 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(dp)
- codeforces-467C-George and Job【dp】
- Codeforce 467C. George and Job(DP)
- [CodeForces 467C]George and Job[DP]
- Codeforces 467C George and Job DP
- Codeforces 467C George and Job(dp)
- CF 267C George and Job
- Codeforces 467C George and Job【dp】好题~
- codeforces 467-C. George and Job(前缀和+dp)
- codefores #267C George and Job(dp)
- C. George and Job
- 企业课堂----关于销售
- 蓝桥杯 历届试题 波动数列 DP 01背包 滚动数组
- 【USACO2.3.2】奶牛家谱 动态规划
- 数据挖掘十大经典算法
- 【项目实战】基于Extjs+SpringMVC+Spring+Mybatis整合的进销存管理系统详解---目录
- CF 467C DP George and Job
- Python初学者的捷径
- 如何做业余项目,我的小实验室、干货好料来分享
- 关于jquery ui dialog 在IE下定位失效的解决办法
- 学习的一个MapReduce程序(《beginner`s guide》中的例子)
- UNIX高级环境编程(2)FIle I/O - 原子操作、共享文件描述符和I/O控制函数
- POJ 3067 Japan
- jQuery UI dialog 的使用
- 06_NoSQL数据库之Redis数据库:Redis的高级应用之登录授权和主从复制