HDU 3001 Travelling (tri-hexadecimal state compression DP)
There are n cities. You can select any city as the starting point. Each city cannot be accessed more than 2 times,
The minimum value required to access all n cities.
Idea: because each city can be accessed for up to two times, the access status is represented in a three-digit format.
For details, see code comments !!!!
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define INF 1e8 # define inf 0x3f3f3f3f # define eps 1e-8 # define LL long # define N 100001 # define mol limit int dp [60000] [15]; // dp [I] [j] indicates that the min value of j is accessed in status I. int g [15] [15]; int n, m; int st [60000] [11]; // dp [I] [j] the number of times that the j City in I state can access int bit [12]; // all initial possible states: int main () {bit [0] = 0; bit [1] = 1; for (int I = 2; I <= 11; I ++) bit [I] = 3 * bit [I-1]; for (int I = 0; I <59050; I ++) {int t = I; for (int j = 1; j <= 10 & t; j ++) {st [I] [j] = t % 3; t/= 3 ;}} while (~ Scanf ("% d", & n, & m) {int u, v, c; memset (dp, 0x3f, sizeof (dp); memset (g, 0x3f, sizeof (g); for (int I = 0; I <= n; I ++) dp [bit [I] [I] = 0; // The initial start point is 0 while (m --) {scanf ("% d", & u, & v, & c); if (c