poj3311(Hie with the Pie)状压dp

2015-07-24 05:52:17 · 作者: · 浏览: 6

题目链接:http://poj.org/problem?id=3311

解法:标准的状压dp类型,先floyd获得两两之间最短距离。然后dp[i][j]表示剩下集合i没走,已经走到j的最短距离;


代码:

/******************************************************
* @author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
           #include 
           
             #include 
            
              #include 
             
               //freopen ("in.txt" , "r" , stdin); using namespace std; #define eps 1e-8 #define zero(_) (abs(_)<=eps) const double pi=acos(-1.0); typedef long long LL; const int Max=15; const int INF=1e9+7; int dist[Max][Max]; int dp[(1<<13)+3][13]; int n; int getans(int st,int la) { if(dp[st][la]!=-1) return dp[st][la]; int ans=INF; for(int i=0; i<=n; i++) { if((st&(1<