Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5418
The main topic: a connected graph (n <16, m<100000) consisting of n nodes M-bar (with Benquan). From the first point, after each point at least once back to the origin of the minimum path edge right and.
Analysis: Found that I was really food.
N<16, it is obvious that the status of the compression tag, first the number of all points minus 1, so that it starts numbering from 0. DP[I][J] means starting from point No. 0, the current state is I (Bits 1 indicates that the corresponding point has traversed, otherwise did not pass), the current position is J, back to the origin of the minimum cost, then dp[(1<<n) -1][0] for the solution, with a similar SPFA method can be updated to all situations.
Reference code:
#include <cstdio>#include<cstring>#include<queue>#include<algorithm>using namespacestd;intdp[1<< -][ -];intmp[ -][ -];intdis[ -];BOOLvis[1<< -][ -];intN;intMain () {intT, M; scanf ("%d", &T); while(t--) {scanf ("%d%d", &n, &m); Memset (MP,0x7f,sizeof(MP)); for(inti =0; I < n; i++) Mp[i][i] =0; for(inti =0; I < m; i++) { intu, V, D; scanf (" %d%d%d", &u, &v, &d); U--; v--; MP[U][V]= Mp[v][u] =min (mp[u][v], D); } memset (DP,0x7f,sizeof(DP)); memset (Vis,0,sizeof(VIS)); dp[0][0] =0, vis[0][0] =1; Queue<pair<int,int> >Q; Q.push (Make_pair (0,0)); while(!Q.empty ()) { ints =Q.front (). First; intU =Q.front (). Second; Q.pop (); for(inti =0; I < n; i++) { intSS = S | (1<<i); if(Dp[ss][i] > Dp[s][u] +Mp[u][i]) {Dp[ss][i]= Dp[s][u] +Mp[u][i]; if(Vis[ss][i] = =0) {Vis[ss][i]=1; Q.push (Make_pair (SS, I)); } } } } //for (int i = 0; l < (1<<n); i++) for (int j = 0; J < N; j + +) printf ("%d%d:%d\n", I, J, Dp[i][j]);printf"%d\n", dp[(1<<n)-1][0]); } return 0;}
HDU 5418 Victor and world (state compression DP)