uva590 - Always on the run(简单动归)
来源:互联网 发布:淘宝宝贝刷收藏软件 编辑:程序博客网 时间:2024/06/08 12:08
状态:dp[i][j]表示第i天到达j号城市的最小花费
状态转移:dp[i][j] = min(dp[i-1][k]);
注意边界是dp[0][1] = 0,而不是dp[1][1] = 0;
代码如下:
#include <cstdio>#include <cstring>#define N 15#define K 1005#define INF 0x7fffffffint n, k, d, dp[K][N], a[N][N][K];int main (){ int tt = 0; while(scanf("%d %d",&n,&k),n+k) { for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { if(i==j) continue; scanf("%d",&d); a[i][j][0] = d; for(int l = 1; l <= d; l++) scanf("%d",&a[i][j][l]); } memset(dp,-1,sizeof(dp)); dp[0][1] = 0; for(int i = 1; i <= k; i++) { for(int j = 1; j <= n; j++) { int &ans = dp[i][j]; ans = INF; for(int l = 1; l <= n; l++) { if(l==j) continue; if(dp[i-1][l]==-1) continue; int num = i%a[l][j][0]; if(num==0) num = a[l][j][0]; int value = a[l][j][num]; if(value==0) continue; ans = ans<dp[i-1][l]+value?ans:dp[i-1][l]+value; } if(ans==INF) ans = -1; } } printf("Scenario #%d\n",++tt); if(dp[k][n]==-1) printf("No flight possible.\n\n"); else printf("The best flight costs %d.\n\n",dp[k][n]); } return 0;}
- uva590 - Always on the run(简单动归)
- UVA590- Always on the run
- 590 - Always on the run
- uva 590 Always on the run
- UVA 590 Always on the run
- UVa 590Always on the run
- POJ-1476-Always on the run
- UVA 590 - Always on the run (dp)
- UVA 590 Always on the run
- UVA - 590 Always on the run
- UVA 590 Always on the run(dp)
- uva 590 - Always on the run
- UVa:590 Always on the run
- uva 590 Always on the run
- uva 590 Always on the run(dp)
- UVA 590 Always on the run | dp
- Always on the run - UVa 590 dp
- uva 590 - Always on the run
- java DOM4J操作XML例子以及DOM、SAX、JDOM、DOM4J的区别
- Ubuntu12.04安装Windows字体
- 计算机常用32个算法
- JVM内存管理及垃圾回收
- MPICH3环境配置
- uva590 - Always on the run(简单动归)
- oracle 之数据字典屣履造门。
- The Most Important Algorithms (in CS and Math)
- 生成图片缩略图
- Maven入门之仓库-第四节
- C++之输出汉字字符
- hdu 1010 Tempter of the Bone
- 不是通过引用或指针调用的话,无法产生多态的效果
- 关节点(atriculation point)算法