Untitled
unknown
plain_text
2 years ago
1.4 kB
5
Indexable
#include <iostream>
using namespace std;
int arr[8][8];
int ard[8] = {0};
int ar[8][8];
int cnt = 0;
int dx[] = { -1, -1, -1, 1, 1, 1};
int dy[] = { -1, 0, 1, -1, 0 , 1};
bool check(int x1, int y1)
{
for(int i = 1; i < 8; i++)
{
for(int j = 0; j < 6; j++)
{
int t = x1 + i * dx[j];
int k = y1 + i * dy[j];
if(t >= 0 && t < 8 && k >= 0 && k < 8)
{
if(ar[t][k] == 2)
{
return false;
}
}
}
}
return true;
}
void xep_hau(int sum, int &max, int index)
{
if(index == 8 )
{
if(max < sum)
{
max = sum;
}
return;
}
for(int j = 0; j < 8; j++)
{
if(check(index, j) == true)
{
ar[index][j] = 2;
xep_hau(sum + arr[index][j], max, index + 1);
ar[index][j] = 0;
}
}
}
int main()
{
//freopen("input.txt", "r+", stdin);
int testcase;
cin >> testcase;
for(int tc = 1; tc <= testcase; tc++)
{
int t1;
cin >> t1;
cout<<"Case #"<<tc<<endl;
for(int tk = 1; tk <= t1; tk++)
{
cnt = 0;
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
cin >> arr[i][j];
}
}
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
ar[i][j] = 0;
}
}
int sum = 0;
int max = 0;
xep_hau(sum, max, 0);
cout<<max<<endl;
}
}
}Editor is loading...