HDU 3001 Travelling (tri-hexadecimal state compression DP)

Source: Internet
Author: User

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
           
            


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.