1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int n,ans; 5 int a[30][30],f[30]; 6 int cmax(int a,int b){return a>b?a:b;} 7 void dfs(int x,int now) 8 { 9 if (x>n) 10 { 11 ans=cmax(ans,now); 12 return; 13 } 14 int temp=0; 15 f[x]=1; 16 for (int i=1;i<x;i++) 17 if (f[i]==0) temp+=a[x][i]; 18 dfs(x+1,now+temp); 19 20 temp=0; 21 f[x]=0; 22 for (int i=1;i<x;i++) 23 if (f[i]==1) temp+=a[x][i]; 24 dfs(x+1,now+temp); 25 } 26 int main() 27 { 28 scanf("%d",&n); 29 memset(f,0,sizeof(f)); 30 ans=0; 31 for (int i=1;i<=n;i++) 32 for (int j=1;j<=n;j++) scanf("%d",&a[i][j]); 33 dfs(1,0); 34 printf("%d\n",ans); 35 return 0; 36 }
时间: 2024-10-08 16:04:45