find the mincost route
来源:互联网 发布:条形码数据采集器用法 编辑:程序博客网 时间:2024/06/06 00:06
find the mincost route
杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须满足K>2,就是说至除了出发点以外至少要经过2个其他不同的景区,而且不能重复经过同一个景区。现在8600需要你帮他找一条这样的路线,并且花费越少越好。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
3 31 2 12 3 11 3 13 31 2 11 2 32 3 1
3It's impossible.
最小环与Floyd算法讲解:
转载:http://blog.sina.com.cn/s/blog_476a25110100mag6.html
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int a[100][100],b[100][100];const int maxn=100000000;int main(){ int i,j,m,n,k; while(scanf("%d %d",&n,&m)!=EOF) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) { a[i][j]=maxn; b[i][j]=maxn; } for(i=0;i<m;i++) { int a1,a2,s; scanf("%d %d %d",&a1,&a2,&s); if(a[a1][a2]>s) a[a1][a2]=a[a2][a1]=b[a1][a2]=b[a2][a1]=s; } int minn=maxn; for(int k=1;k<=n;k++) { for(int i=1;i<k;i++) for(int j=i+1;j<k;j++) minn=min(minn,b[i][j]+a[i][k]+a[k][j]); for(int i=1;i<n;i++) for(int j=1;j<=n;j++) b[i][j]=min(b[i][k]+b[k][j],b[i][j]); } if(minn>=maxn) printf("It's impossible.\n"); else printf("%d\n",minn); } return 0;}
阅读全文
0 0
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- HDU1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 find the mincost route
- Hdoj find the mincost route
- find the mincost route hdoj1599
- HDU1599:find the mincost route
- HDU_1599 find the mincost route
- find the mincost route HDU
- hdu1599 find the mincost route
- [hdu1599]find the mincost route
- 常用SQL命令
- eclipse/android studio下如何使用第三方模拟器
- Ubuntu安装cuDNN
- Unique Paths II
- SPI协议及其工作原理浅析
- find the mincost route
- hiho #1539 : 数组重排3(bfs)
- C++抽象设计目的
- 正则表达式之过滤敏感词
- linux下c语言入门04 main函数的编写
- XML
- 同步函数与异步函数
- 【重磅】微软AI首席科学家邓力:深度学习技术及趋势报告(75页PPT下载)
- 手把手教你利用Jenkins持续集成iOS项目