uva167 The Sultan's Successors

简介: uva167 The Sultan's Successors
#include <stdio.h>#include <string.h>#define MAXN 8inta[MAXN][MAXN], vis[3][2*MAXN];
intnum, ans;
voiddfs(intcur);
intmain()
{
intk, i, j, l;
#ifndef ONLINE_JUDGEfreopen("d:\\uva_in.txt", "r", stdin);
#endifscanf("%d", &k);
for (i=0; i<k; i++) {
for (j=0; j<MAXN; j++)
for (l=0; l<MAXN; l++)
scanf("%d", &a[j][l]);
memset(vis, 0, sizeof(vis));
ans=0;
num=0;
dfs(0);
printf("%5d\n", ans);
    }
return0;
}
voiddfs(intcur)
{
inti;
if (cur==MAXN) {
if (num>ans)
ans=num;
    } else {
for (i=0; i<MAXN; i++) {
if (!vis[0][i] &&!vis[1][cur+i] &&!vis[2][i-cur+MAXN]) {
vis[0][i] =vis[1][cur+i] =vis[2][i-cur+MAXN] =1;
num+=a[cur][i];
dfs(cur+1);
num-=a[cur][i];
vis[0][i] =vis[1][cur+i] =vis[2][i-cur+MAXN] =0;
            }
        }
    }
}
目录
相关文章
UVa11679 - Sub-prime
UVa11679 - Sub-prime
56 0
uva10783 Odd Sum
uva10783 Odd Sum
52 0
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
111 0
|
人工智能 Java
Math - Uva 11300 Spreading the Wealth
Spreading the Wealth  Problem's Link  ---------------------------------------------------------------------------- Mean:  n个人围成一圈,每个人手里有Ai个金币,每个人可以给与他相邻的人一些金币,通过一系列的流转后,最后所有人的金币数相等。
1026 0
|
机器学习/深度学习 Java Go