POJ - 3311 Hie with the Pie
来源:互联网 发布:linux vi编辑怎么换行 编辑:程序博客网 时间:2024/06/07 07:25
1.题面
http://poj.org/problem?id=3311
2.题意
给你n个点,已知两两之间的距离,让你用最短的时间走完n个点,一个点可以走多次,求最短时间
3.思路
瞎写了一发,居然过了。。。。
4.代码
/***************************************************************** > File Name: Cpp_Acm.cpp > Author: Uncle_Sugar > Mail: uncle_sugar@qq.com > Created Time: 2016年07月28日 星期四 08时57分03秒*****************************************************************/# include <cstdio># include <cstring># include <cctype># include <cmath># include <cstdlib># include <climits># include <iostream># include <iomanip># include <set># include <map># include <vector># include <stack># include <queue># include <algorithm>using namespace std;template<class T>void PrintArray(T* first,T* last,char delim=' '){ for (;first!=last;first++) cout << *first << (first+1==last?'\n':delim); }const int debug = 1;const int size = 10 + 10 ; const int INF = INT_MAX>>1;typedef long long ll;int n;int dist[size][size];void floyd(){for (int k=0;k<n;k++){for (int i=0;i<n;i++){for (int j=0;j<n;j++){dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);}}}}int dp[20][1<<11];int main(){std::ios::sync_with_stdio(false);cin.tie(0);int i,j;while (cin >> n){if (n==0) break;n++;for (i=0;i<n;i++){for (j=0;j<n;j++){cin >> dist[i][j];}}floyd();for (i=0;i<20;i++){for (j=0;j<=(1<<n);j++){dp[i][j] = INF;}}dp[0][(1<<n)-1] = 0;for (int s=(1<<n);s>=0;s--){for (int u=0;u<n;u++){for (int v=0;v<n;v++){if (!(s&(1<<v)))dp[u][s] = min(dp[u][s],dp[v][s|(1<<v)]+dist[v][u]);}}}cout << dp[0][0] << endl;}return 0;}
0 0
- poj 3311 Hie with the Pie
- POJ 3311 Hie with the Pie
- poj 3311 Hie with the Pie
- poj 3311 Hie with the Pie
- poj 3311 Hie with the Pie (TSP)
- POJ 3311 — Hie with the Pie
- POJ 3311 Hie with the Pie
- poj 3311 Hie with the Pie (DP)
- POJ 3311 Hie with the Pie
- POJ 3311 Hie with the Pie
- POJ - 3311 Hie with the Pie
- POJ 3311 - Hie with the Pie
- POJ 3311 Hie with the Pie
- POJ 3311 Hie with the Pie
- Hie with the Pie POJ
- Hie with the Pie POJ
- Hie with the Pie POJ
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- 今天太阳了一条狗!大悲咒走起
- Hadoop:NameNode和Secondary NameNode
- #vsftpd.config文件文档
- C语言中比较好的方法
- 汇编指令
- POJ - 3311 Hie with the Pie
- 使用官方 docker registry 搭建私有镜像仓库及部署 web ui
- nyoj 860 又见01背包(01 背包)
- 【1】【状压DP】POJ3311 Hie with the Pie
- 学习用例:js中回文的处理
- Hadoop:HDFS文件存取机制
- ld: cannot find -lc
- ContextLoaderListener和Spring MVC中的DispatcherServlet加载内容的区别
- Pro JPA2读书笔记系列(十一)-第十章(高级对象-关系映射)