Zaban ah, their own bit arithmetic is not at all ah, had to let big brother Kankan room with big brother told me the code
Code:
. 1 #include <bits / STDC ++ H.> 2 the using namespace STD; . 3 const int N = 1e6 + . 7 ; . 4 const int INF = 0x3f3f3f3f ; . 5 int n-, m; . 6 int G [N]; // G [I] i represents the point can reach all points . 7 int DP [N] [ 21 is ]; // DP [i] [k] represents the state i to go spent reaches step k . 8 int DIS [ 21 is ] [ 21 is ]; // save side . 9 int main () { 10 Scanf (" % D% D " , & n-, & m); . 11 Memset (DIS, 0x3F , the sizeof DIS); 12 is for ( int I = . 1 ; I <= m; I ++ ) { 13 is int U, V, W; 14 Scanf ( " % D% D% D " , & U, V &, & W); 15 u - the, V -; // here - since after the position calculation will be more convenient to 16 DIS [U] [V ] = DIS [V] [U] = min (DIS [U] [V], W); // have multiple edges . 17 } 18 is int All = ( . 1 << n-) -. 1 ; . 19 for ( int I = . 1 ; I <= All; I ++) { // enumerate all state 20 is for ( int J = 0 ; J <n-; J ++) { // enumerate all points 21 is IF (( . 1 J <<) & i) { // if the state comprising i J 22 is DIS [J] [J] = 0 ; // initialize to himself 0 23 is for ( int K = 0 ; K <n-; K ++ ) { 24 IF (DIS [J] [K]! = INF) { 25 G [I] | = ( . 1 << K); // all the tags can reach 26 is } 27 } 28 } 29 } 30 } 31 is Memset (DP, 0x3F , the sizeof DP); 32 for ( int I = 0 ; I <n-; I ++ ) { 33 is DP [ . 1 << I] [ 0 ] = 0 ; // spent not take the time to 0 34 is } 35 for ( int= I 2 ; I <= All; I ++) { // enumerate all states, 2 from the start because of their own, and only an empty set, regardless of 36 for ( int J = I - 1 ; J; J = ( j - . 1 ) & i) { // enumeration subset of state i 37 [ IF ((G [j] | i) == G [j]) { // if i j to reach the state 38 is int SUM = 0 ; 39 int rEST J ^ = I; // remove remaining not been to point 40 for ( int K = 0 ; K <n-; K ++) { // enumerate all end points 41 is IF (( . 1 << K) & rEST ) { //If it is not to rest over point 42 is int tmp = INF; 43 is for ( int H = 0 ; H <n-; H ++) { // Enumeration starting point 44 is IF (( . 1 << H) & J) { / / If the point j in the state 45 tmp min = (tmp, DIS [H] [K]); // update 46 is } 47 } 48 SUM + = tmp; // calculate the total minimum cost from state i to state j 49 } 50 } 51 is for (int K = . 1 ; K <n-; K ++ ) { 52 is IF (DP [J] [K - . 1 ] == INF) Continue ; // Previous not reach the skip 53 is DP [I] [K] = min ( DP [I] [K], DP [J] [K - . 1 ] + SUM * K); // update 54 is } 55 } 56 is } 57 is } 58 int ANS = INF; 59 for ( int I = 0 ; I < n-; I ++ ) { 60 ANS = min (ANS, DP [All] [I]); //Find the minimum value of 61 is } 62 is the printf ( " % D \ n- " , ANS); 63 is return 0 ; 64 }
No, not refuel!