【HDU 1599 find the mincost route 】
来源:互联网 发布:excel怎么建立数据库 编辑:程序博客网 时间:2024/05/17 18:14
find the mincost route
Problem Description
杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,….VK,V1,那么必须满足K>2,就是说至除了出发点以外至少要经过2个其他不同的景区,而且不能重复经过同一个景区。现在8600需要你帮他找一条这样的路线,并且花费越少越好。
Input
第一行是2个整数N和M(N <= 100, M <= 1000),代表景区的个数和道路的条数。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
Output
对于每个测试实例,如果能找到这样一条路线的话,输出花费的最小值。如果找不到的话,输出”It’s impossible.”.
Sample Input
3 3
1 2 1
2 3 1
1 3 1
3 3
1 2 1
1 2 3
2 3 1
Sample Output
3
It’s impossible.
Author
上午刚做过~~下午又遇到了~~
两个数组一个存相邻边,一个存到任意点的最短路
#include<cstdio>#include<algorithm>using namespace std;const int INF=0x3f3f3f;int N,M;int dp[1010][1010];int ma[1010][1010];void floyd(){ int k,i,j,ans=INF; for(k=1;k<=N;k++) { for(i=1;i<k;i++) for(j=i+1;j<k;j++) ans=min(ans,dp[i][k]+dp[k][j]+ma[i][j]);//找到不经过 k 点时的最短路 for(i=1;i<=N;i++) for(j=1;j<=N;j++) ma[i][j]=min(ma[i][j],ma[i][k]+ma[k][j]); } if(ans==INF) printf("It's impossible.\n"); else printf("%d\n",ans);}int main(){ int i,j,a,b,c; while(scanf("%d%d",&N,&M)!=EOF) { for(i=1;i<=N;i++) for(j=1;j<=N;j++) { if(i==j) dp[i][j]=ma[i][j]=0; else dp[i][j]=ma[i][j]=INF; } while(M--) { scanf("%d%d%d",&a,&b,&c); if(c<dp[a][b]) dp[a][b]=dp[b][a]=ma[a][b]=ma[b][a]=c; } floyd(); } return 0;}
0 0
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- 【HDU 1599 find the mincost route】
- HDU 1599 find the mincost route
- 【HDU 1599 find the mincost route 】
- HDU 1599 find the mincost route
- HDU-1599-find the mincost route
- Android 实现点击两次退出
- C. Terse princess
- HDU 1599 find the mincost route
- Caught exception while loading file com/crud/action/LoginAction-validation.xml
- Orcale 视频知识点总结
- 【HDU 1599 find the mincost route 】
- <LeetCode OJ> 387. First Unique Character in a String
- Graphviz样例之有向图
- 面试总结(static、const、define)
- Freeline - Android平台上的秒级编译方案
- Android5.0以上版本ActiveAndroid报ClassNotFoundException错误
- NumPy学习笔记
- UIView之动画效果的实现方法(合集)
- android捕获back键