以下為模板:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<limits.h> | |
#include<algorithm> | |
#define MAXN 16 | |
int n;/*點數*/ | |
int dp[MAXN][1<<MAXN];/*DP陣列*/ | |
int g[MAXN][MAXN];/*圖*/ | |
int dfs(int s,int d){ | |
if(dp[d][s])return dp[d][s]; | |
if((1<<d)==s)return g[0][d]; | |
dp[d][s]=INT_MAX; | |
for(int i=0;i<n;++i){ | |
if(((1<<i)&s)&&i!=d){ | |
dp[d][s]=std::min(dp[d][s],dfs(s^(1<<d),i)+g[i][d]); | |
} | |
} | |
return dp[d][s]; | |
} |
沒有留言:
張貼留言