Create 2531_martin31hao.cpp

From http://blog.csdn.net/martin31hao/article/details/8098302
This commit is contained in:
Kirigaya Kazuto 2016-09-01 20:22:43 +08:00 committed by GitHub
parent f10d9ad19c
commit f920a37956

45
POJ/2531_martin31hao.cpp Normal file
View File

@ -0,0 +1,45 @@
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 30;
int n, ans;
int a[maxn][maxn];
int dep[maxn];
void dfs(int id, int data)
{
dep[id] = 1;
int tmp = data;
for(int i = 1; i <= n; i ++)
{
if(dep[i] == 0)
tmp += a[i][id];
else
tmp -= a[i][id];
}
if(ans < tmp)
ans = tmp;
for(int i = id + 1; i <= n; i ++)
{
if(tmp > data)
{
dfs(i, tmp);
dep[i] = 0;
}
}
}
int main()
{
while(~scanf("%d", &n))
{
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
scanf("%d", &a[i][j]);
memset(dep, 0, sizeof(dep));
ans = 0;
dfs(1, 0);
printf("%d\n", ans);
}
}