POJ - 3311 Hie with the Pie
2016-07-28 10:23
281 查看
1.题面
http://poj.org/problem?id=33112.题意
给你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;
}
相关文章推荐
- VS2008快捷键总结
- UIScrollView的循环滚动+UIPageControll
- UVA 11149 Power of Matrix(矩阵+二分)
- Android开发笔记(-)初识Android中的px,sp,dp
- GitHub相关
- Pro JPA2读书笔记系列(十二)-第十一章(高级主题)
- QProcess::readAll() 函数
- Hadoop:HDFS的数据复制
- udev使用方法(附实例)
- 易买网项目总结
- seajs
- 多媒体应用-swift
- C++ STL--stack/queue 的使用方法
- HDU 4588 Count The Carries(数学)
- 获取字符中Url地址
- mysql 字符集(CHARACTER SET)和校对集(COLLATE)
- 网络请求xml PULL解析
- 友盟统计使用记录
- SVN服务器搭建 <1>
- Pro JPA2读书笔记系列(十一)-第十章(高级对象-关系映射)