poj 3042 Grazing on the Run
来源:互联网 发布:我的世界json 编辑:程序博客网 时间:2024/06/10 21:00
这个题目原型应该是吃完所有的草丛的最小时间,现在变成了每个草丛被吃的时间和,貌似如果还是按照原来的dp方法dp[i][j]表示吃完i到j的草丛的花掉的时间的话,有两个因素会影响后面的决策,一个是花掉的时间,一个是吃掉的草丛的时间累加和。
但是仔细观察这个问题会发现,第一个走的距离,会被计算n次,第二个走的距离,会被计算n-1次。如果我们把这个代价转移到该草丛上的话。那么dp[i][j]表示转移后的花掉的时间,那么现在影响后面决策的就只有这个时间了。那么问题就解决了。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=1e3+9;int n,l;int a[maxn],dp[maxn][maxn][2];int main(){// freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&l)!=EOF) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); n++;a[n]=l; sort(a+1,a+1+n); int t=lower_bound(a+1,a+n,l)-a; memset(dp,50,sizeof(dp)); dp[t][t][0]=0; for(int k=0;k<n-1;k++) for(int i=max(1,t-k);i<=min(n,t+k);i++) { dp[i-1][i+k][0]=min(dp[i][i+k][0]+(a[i]-a[i-1])*(n-k-1),dp[i][i+k][1]+(a[i+k]-a[i-1])*(n-k-1)); dp[i][i+k+1][1]=min(dp[i][i+k][0]+(a[i+k+1]-a[i])*(n-k-1),dp[i][i+k][1]+(a[i+k+1]-a[i+k])*(n-k-1)); } int ans=min(dp[1][n][0],dp[1][n][1]); cout<<ans<<endl; } return 0;}
- POJ 3042 Grazing on the Run
- poj 3042 Grazing on the Run
- poj 3042 Grazing on the Run(区间DP,三维DP)
- POJ 3042 Grazing on the Run (区间DP)
- POJ 3042 Grazing on the Run 区间dp
- POJ 3042 Grazing on the Run (三维区间DP)【区间DP模板】
- poj3042 Grazing on the Run[区间dp]
- 1694: [Usaco2007 Demo]Grazing on the Run
- BZOJ 1694 [Usaco2007 Demo]Grazing on the Run DP
- 【bzoj1742】[Usaco2005 nov]Grazing on the Run 边跑边吃草
- [bzoj1742][Usaco2005 nov][DP]Grazing on the Run 边跑边吃草
- [Usaco2005 Nov Gold]Grazing on the Run奶牛吃草-Dp 移动类
- BZOJ 1742 Usaco2005 nov Grazing on the Run 边跑边吃草 动态规划
- 【BZOJ1742】[Usaco2005 nov]Grazing on the Run 边跑边吃草【区间DP】
- bzoj 1694 && 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草(DP)
- POJ-1476-Always on the run
- UVa10678 - The Grazing Cow
- 590 - Always on the run
- servlet学习笔记3——用户登录网站(通过session验证登陆用户)
- 调试器工作原理之一——基础篇
- 数据对接—kettle使用之五
- 'nmake' 不是内部或外部命令,也不是可运行的程序或批处理文件
- Hadoop开发常用的InputFormat和OutputFormat
- poj 3042 Grazing on the Run
- PowerHA 6.1 DARE 的功能介绍
- cocos2d-x-3.0
- 数据对接—kettle使用之六
- { 反思 }soj1703
- Log4J详细配置-输出到日志文件中(下一讲讲解输出到数据库中)
- jQuery基础教程第七章学习
- 随笔2013,10.30
- 带你走进EJB--将EJB发布为Webservice(1)