博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zoj 1232 Adventure of Super Mario
阅读量:5322 次
发布时间:2019-06-14

本文共 3462 字,大约阅读时间需要 11 分钟。

ZOJ Problem Set - 1232
Adventure of Super Mario

Time Limit: 2 Seconds     
Memory Limit: 65536 KB

After rescuing the beautiful princess, Super Mario needs to find a way home -- with the princess of course :-) He's very familiar with the 'Super Mario World', so he doesn't need a map, he only needs the best route in order to save time.

There are A Villages and B Castles in the world. Villages are numbered 1..A, and Castles are numbered A+1..A+B. Mario lives in Village 1, and the castle he starts from is numbered A+B. Also, there are two-way roads connecting them. Two places are connected by at most one road and a place never has a road connecting to itself. Mario has already measured the length of every road, but they don't want to walk all the time, since he walks one unit time for one unit distance(how slow!).

Luckily, in the Castle where he saved the princess, Mario found a magic boot. If he wears it, he can super-run from one place to another IN NO TIME. (Don't worry about the princess, Mario has found a way to take her with him when super-running, but he wouldn't tell you :-P)

Since there are traps in the Castles, Mario NEVER super-runs through a Castle. He always stops when there is a castle on the way. Also, he starts/stops super-runnings ONLY at Villages or Castles.

Unfortunately, the magic boot is too old, so he cannot use it to cover more than L kilometers at a time, and he cannot use more than K times in total. When he comes back home, he can have it repaired and make it usable again.

Input

The first line in the input contains a single integer T, indicating the number of test cases. (1<=T<=20) Each test case begins with five integers A, B, M, L and K -- the number of Villages, the number of Castles(1<=A,B<=50), the number of roads, the maximal distance that can be covered at a time(1<=L<=500), and the number of times the boot can be used. (0<=K<=10) The next M lines each contains three integers Xi, Yi, Li. That means there is a road connecting place Xi and Yi. The distance is Li, so the walk time is also Li. (1<=Li<=100)

Output

For each test case in the input print a line containing a single integer indicating the minimal time needed to go home with the beautiful princess. It's guaranteed that Super Mario can always go home.

Sample Input

1

4 2 6 9 1
4 6 1
5 6 10
4 5 5
3 5 4
2 3 4
1 2 3

Sample Output

9


Source: OIBH Reminiscence Programming Contest //floyd+dp //先求出任意2点之间的最短距离 //dp[i][j]代表通过前i-1个点走到第 i 点,用了j次鞋子的最小时间; //can[i][j]=1 代表该2点可以用鞋子到达 #include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define N 102#define Max 1000000000int map[N][N];bool can[N][N];int dp[N][11];int main(){ int T; int A,B,M,L,K; int n; int i,j,k; scanf("%d",&T); while(T--) { scanf("%d %d %d %d %d",&A,&B,&M,&L,&K); n=A+B; for(i=1;i<=n;i++) for(j=1;j<=n;j++) map[i][j]=Max,can[i][j]=0; while(M--) { scanf("%d %d %d",&i,&j,&k); map[i][j]=map[j][i]=k; if(map[i][j]<=L) can[i][j]=can[j][i]=1; } for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(map[i][j]>map[i][k]+map[k][j]) { map[i][j]=map[i][k]+map[k][j]; if(k<=A&&map[i][j]<=L) can[i][j]=1; } // memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) dp[i][0]=map[1][i]; dp[1][0]=0; int temp; for(i=2;i<=n;i++) { for(j=1;j<=K;j++) { temp=Max; for(k=1;k

转载于:https://www.cnblogs.com/372465774y/archive/2012/11/20/2779477.html

你可能感兴趣的文章
测试用例设计步骤及方法
查看>>
探究光线追踪技术及UE4的实现
查看>>
深入GPU硬件架构及运行机制
查看>>
javascript百度地图使用(根据地名定位、根据经纬度定位)
查看>>
js拖拽上传图片
查看>>
zabbx 监控安装部署及操作
查看>>
redis 数据库架构安装部署及操作
查看>>
mysql 架构安装部署及操作
查看>>
shell
查看>>
路由器怎么设置无线上网
查看>>
使用MBROSTool 工具制作U盘多启动盘的方法总结
查看>>
使用的组件:Jcrop
查看>>
itnba试做
查看>>
HDU-5776 Sum
查看>>
Hadoop初期学习和集群搭建
查看>>
《必然》五、屏幕只把我们变成近视眼吗,远远不止
查看>>
Hadoop-2.2.0集群安装配置实践
查看>>
cache max-age tags context
查看>>
VMware虚拟机上centos安装
查看>>
maven setting.xml
查看>>