#include <iostream>
using namespace std;
#define N 8
int c[N] = {-1};
int a[N][N];
int k[1000];
int tong, m;
void Queen(int n)
{
if(n == N)
{
if(tong > m) m = tong;
}
bool check;
for (int i = 0; i < N; i++)
{
check = true;
for(int q = 0; q < n; q++)
if(c[q] == i || q + c[q] == n+i || q - c[q] == n - i)
check = false;
if(check)
{
c[n] = i;
tong = tong + a[n][i];
Queen(n+1);
c[n] = -1;
tong = tong - a[n][i];
}
}
}
int main()
{
int T,n;
freopen("input.txt","r",stdin);
cin >> T;
for (int tc = 1; tc <= T; tc ++)
{
cin >> n;
cout << "Case " << "#" << tc << endl;
for( int t = 0; t < n; t++)
{
for(int i = 0; i < 8; i++)
for(int j = 0; j < 8; j++)
cin >> a[i][j];
tong=0;
m=0;
Queen(0);
cout << m << endl;
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.