标签:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 9531 | Accepted: 4533 |
Description
Input
Output
Sample Input
3 0 50 30 50 0 40 30 40 0
Sample Output
90
Source
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> #include<cstdlib> #include<queue> using namespace std; int n,a[30][30],ans,vis[30]; void dfs(int x) { vis[x]=1; int cnt=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(vis[i]&&!vis[j]) cnt+=a[i][j]; } } if(cnt>ans) ans=cnt; for(int i=x+1;i<n;i++) { dfs(i); vis[i]=0; } } int main() { while(scanf("%d",&n)!=EOF) { ans=0; for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d",&a[i][j]); memset(vis,0,sizeof(vis)); dfs(0); printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4287798.html