标签:efi cin int problem string ble put 剪枝 ring
3 10 2 3 2 3 4 3 4 5
9
1 #include <iostream> 2 #include <algorithm> 3 #include <string.h> 4 #include <string> 5 #include <map> 6 7 #define inf 0x3f3f3f3f 8 9 using namespace std; 10 11 int a[25][25], book[25]; 12 int minn; 13 14 void dfs(int cur, int sum, int n) 15 { 16 if(sum >= minn) return; 17 else if(cur==n) minn = min(minn, sum); 18 else 19 { 20 int i; 21 for(i=0;i<n;i++) 22 { 23 if(book[i]==0) 24 { 25 book[i] = 1; 26 dfs(cur+1, sum+a[cur][i], n); 27 book[i] = 0; 28 } 29 } 30 } 31 } 32 33 int main() 34 { 35 int n, i, j; 36 cin >> n; 37 for(i=0;i<n;i++) 38 { 39 for(j=0;j<n;j++) 40 { 41 cin >> a[i][j]; 42 } 43 } 44 minn = inf; 45 dfs(0, 0, n); 46 cout << minn << endl; 47 return 0; 48 }
标签:efi cin int problem string ble put 剪枝 ring
原文地址:https://www.cnblogs.com/0xiaoyu/p/14100587.html