uva 590 Always on the run
来源:互联网 发布:怎样使用淘宝直通车 编辑:程序博客网 时间:2024/04/30 14:48
题意:先给你两个整数,n,k表示城市与要乘坐的航班数。
接下来的n(n-1)行分别表示每两个城市之间的价格情况,第一个n-1行表示从城市1到其他的城市(2,3。。。n),第二个n-1行表示从城市2到其他的城市(1,3。。。n)。问是否能从城市1出发,经过k次航班到达城市n,如果可以输出所需的最小花费,否则输出No flight possible.
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define INF 1<<30#define bug printf("here\n");struct node{ int cnt,day[35];}flight[12][12];int n,k,map[12][1005],dp(int,int);bool vis[12][1005];int main(){ int t_cnt=0; while(scanf("%d%d",&n,&k)!=EOF) { if(n==0&&k==0) break; memset(vis,0,sizeof(vis)); memset(map,0,sizeof(map)); memset(flight,0,sizeof(flight)); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j) continue; scanf("%d",&flight[i][j].cnt); for(int k=0;k<flight[i][j].cnt;k++) { scanf("%d",&flight[i][j].day[k]); } } } int temp=dp(0,0); printf("Scenario #%d\n",++t_cnt); if(temp!=INF) printf("The best flight costs %d.\n\n",temp); else puts("No flight possible.\n"); } return 0;}int dp(int x,int y){ if(vis[x][y]) return map[x][y]; else if(y==k) { vis[x][y]=1; if(x==n-1) map[x][y]=0; else map[x][y]=INF; return map[x][y]; } else { int imin=INF; for(int i=0;i<n;i++) { if(i==x) continue; int nday=flight[x][i].cnt; if(flight[x][i].day[y%nday]) { int temp=dp(i,y+1); if(temp!=INF) imin=min(imin,temp+flight[x][i].day[y%nday]); } } vis[x][y]=1; map[x][y]=imin; return imin; }}
- 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
- 我眼中的云--历史的云
- ajax get和post请求
- 如何提高英文的科研写作能力-施一公
- ARM-Linux移植之(四)——根文件系统构建
- grep
- uva 590 Always on the run
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第一篇:准备工作
- 两张足以吓跑Groupon投资者的图
- FastIO
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第二篇:第一个页面
- 请教高手关于delphi中的一个问题
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第三篇:ASP.NET MVC全局观
- 前台控制后台方法来控制样式。
- alpha shape