HDOJ 5418 Victor and World 状压DP
来源:互联网 发布:齐天大肾余潇洒知乎 编辑:程序博客网 时间:2024/05/25 19:58
水状压DP
Victor and World
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 407 Accepted Submission(s): 164
Problem Description
After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fly around the world. There are n countries on the earth, which are numbered from 1 to n . They are connected by m undirected flights, detailedly the i -th flight connects the ui -th and the vi -th country, and it will cost Victor's airplane wi L fuel if Victor flies through it. And it is possible for him to fly to every country from the first country.
Victor now is at the country whose number is1 , he wants to know the minimal amount of fuel for him to visit every country at least once and finally return to the first country.
Victor now is at the country whose number is
Input
The first line of the input contains an integer T , denoting the number of test cases.
In every test case, there are two integersn and m in the first line, denoting the number of the countries and the number of the flights.
Then there arem lines, each line contains three integers ui , vi and wi , describing a flight.
1≤T≤20 .
1≤n≤16 .
1≤m≤100000 .
1≤wi≤100 .
1≤ui,vi≤n .
In every test case, there are two integers
Then there are
Output
Your program should print T lines : the i -th of these should contain a single integer, denoting the minimal amount of fuel for Victor to finish the travel.
Sample Input
13 21 2 21 3 3
Sample Output
10
Source
BestCoder Round #52 (div.2)
/* ***********************************************Author :CKbossCreated Time :2015年08月23日 星期日 10时27分21秒File Name :HDOJ5418.cpp************************************************ */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>#include <cassert>using namespace std;typedef long long int LL;const int INF=0x3f3f3f3f;int n,m;int G[18][18];int dp[18][1<<18];int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int T_T;scanf("%d",&T_T);while(T_T--){scanf("%d%d",&n,&m);memset(G,63,sizeof(G));for(int i=0;i<n;i++) G[i][i]=0;for(int i=0,a,b,c;i<m;i++){scanf("%d%d%d",&a,&b,&c);a--; b--;G[a][b]=min(G[a][b],c);G[b][a]=min(G[b][a],c);}for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)G[i][j]=min(G[i][j],G[i][k]+G[k][j]);memset(dp,63,sizeof(dp));dp[0][1]=0;for(int i=1;i<(1<<n);i++) /// status{for(int j=0;j<n;j++) /// from point{if(((1<<j)&i)!=0){for(int k=0;k<n;k++) /// to point{if(((1<<k)&i)==0){dp[k][((1<<k)|i)]=min(dp[k][((1<<k)|i)],dp[j][i]+G[j][k]);}}}}}int ans=INF;for(int i=0;i<n;i++){ans=min(ans,dp[i][(1<<n)-1]+G[i][0]);}if(n==1) ans=0;printf("%d\n",ans);} return 0;}
1 0
- 【HDOJ 5418】 Victor and World (状压dp)
- HDOJ 5418 Victor and World 状压DP
- HDOJ 5418 Victor and World
- hdu 5418 Victor and World 状压DP
- hdu 5418 Victor and World (floyd+状压dp)
- hdu 5418 Victor and World(floyd+状压dp)
- HDU 5418 Victor and World(状压dp、最短路)
- hdu 5418 Victor and World(dp)
- hdu5418--Victor and World(floyd+状压dp)
- HDU-5418 Victor and World(状压+spfa)
- hdu--5418Victor and World+状态压缩DP
- HDU 5418 Victor and World(状压dp、floy最短路)
- hdu 5418 Victor and World
- hdu 5418 Victor and World
- HUD 5418 Victor and World
- hdu 5418 Victor and World【状态压缩】
- hdu 5418 Victor and World 状态压缩dp spfa最短路 floyed最短路
- BestCoder Round #52 (div.2) HDU 5418 Victor and World (DP+状态压缩)
- Windows 7环境下安装Apache Http Server 2.2.19
- 数据结构之链表
- 异常 -- 捕获处理 &抛出处理
- jsp基础语法
- oracle学习笔记——表空间管理
- HDOJ 5418 Victor and World 状压DP
- 局部敏感哈希 locality sensitive hashing
- Druid连接池二(学习笔记)
- Delphi中常用的各个关键字名称及用法
- CodeForces 543A-Writing Code
- Linux内核工程导论——前言
- Detours -- Hook API (MessageBoxW)
- hdoj 5137 How Many Maos Does the Guanxi Worth【最短路 Floyd】
- Navicat for MySql 导入txt数据时1366错误