UVA 590 - Always on the run
来源:互联网 发布:javascript项目实战 编辑:程序博客网 时间:2024/06/14 04:11
第一次把题意理解错了,第二次因为一个 ] ,wrong了四次,还好在极值样例的检测下,找出来了。以后打代码一定要注意了。
我是这样定义状态的,f[i][j]表示在第i天时,在城市j所花费的最小费用,很简单的dp题:
代码如下:
#include<stdio.h>#include<string.h>#define INF 2000000000long long b[15][15][35];long long f[1010][15];int n, k, num;void output(){ if(f[k+1][n] < INF)printf("The best flight costs %lld.\n",f[k+1][n]); else printf("No flight possible.\n"); printf("\n");}void solve(){ for(int i = 2; i <= n; i ++) f[1][i] = INF; f[1][1] = 0; for(int i = 2; i <= k+1; i ++) for(int j = 1; j <= n; j ++) { f[i][j] = INF; for(int g = 1; g <= n; g ++) if(g != j && f[i-1][g] != INF) { if((i-1)%b[g][j][0]&&f[i-1][g]+b[g][j][(i-1)%b[g][j][0]] < f[i][j]) f[i][j] = f[i-1][g] + b[g][j][(i-1)%b[g][j][0]]; if(!((i-1)%b[g][j][0]) && f[i-1][g] + b[g][j][b[g][j][0]] < f[i][j]) f[i][j] = f[i-1][g] + b[g][j][b[g][j][0]]; } } output();}void input(){ while(scanf("%d%d",&n, &k) == 2) { if(n==0&&k==0) break; for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) if(i != j) { scanf("%d",&b[i][j][0]); for(int g = 1; g <= b[i][j][0]; g ++) { scanf("%d",&b[i][j][g]); if(b[i][j][g] == 0) b[i][j][g] = INF; } } printf("Scenario #%d\n",++num); solve(); }}int main(){ num = 0; input(); return 0;}
0 0
- uva 590 Always on the run
- UVA 590 Always on the run
- UVa 590Always 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
- 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
- POJ 2785 4 Values whose Sum is 0
- UVA 10534 - Wavio Sequence
- CSU 1080: A simple maze
- UVA 10651 - Pebble Solitaire
- CSU 1248: 非变性聚丙烯酰胺凝胶电泳
- UVA 590 - Always on the run
- UVA 10306 - e-Coins
- UVA 10739 - String to Palindrome
- UVA 10304 - Optimal Binary Search Tree
- UVA 10271 - Chopsticks
- 第一周项目3 时间程序
- UVA 10617 - Again Palindrome
- C++时间标准库时间time和系统时间的使用
- UVA 11081 - Strings