#include<stdio.h>
int n,ans = 0,map[21][21],set[21];
void dfs(int x, int sum)
{
int i,m;
if(x>n)
{
if(sum > ans)
ans = sum;
return;
}
m = 0;
set[x] = 1;
for(i = 1; i <= x; i ++)
if(set[i] == 2)
m += map[i][x];
dfs(x + 1, sum + m);
m = 0;
set[x] = 2;
for(i = 1; i <= x; i ++)
if(set[i] == 1)
m += map[i][x];
dfs(x + 1, sum + m);
}
int main()
{
int i,j;
scanf("%d",&n);
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
scanf("%d",&map[i][j]);
dfs(1, 0);
printf("%d\n",ans);
return 0;
}
转载于:https://www.cnblogs.com/You-Change/p/3468087.html