You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 110;
|
|
|
|
|
const int M = 30; //偏移量
|
|
|
|
|
int n, m; // n行m列
|
|
|
|
|
int ans[N][N];
|
|
|
|
|
int a[N]; //正对角线
|
|
|
|
|
int b[N]; //反对角线
|
|
|
|
|
|
|
|
|
|
void dfs(int x, int y, int sum) {
|
|
|
|
|
if (x == n + 1) {
|
|
|
|
|
ans[n][m] = max(ans[n][m], sum);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果这个位置可以放,那么我们可以选择放
|
|
|
|
|
if (!a[x + y] && !b[x - y + M]) {
|
|
|
|
|
a[x + y] = 1;
|
|
|
|
|
b[x - y + M] = 1;
|
|
|
|
|
|
|
|
|
|
if (y == m)
|
|
|
|
|
dfs(x + 1, 1, sum + 1);
|
|
|
|
|
else
|
|
|
|
|
dfs(x, y + 1, sum + 1);
|
|
|
|
|
|
|
|
|
|
a[x + y] = 0;
|
|
|
|
|
b[x - y + M] = 0;
|
|
|
|
|
}
|
|
|
|
|
//不管可以不可以放,都可以选择不放
|
|
|
|
|
if (y == m)
|
|
|
|
|
dfs(x + 1, 1, sum);
|
|
|
|
|
else
|
|
|
|
|
dfs(x, y + 1, sum);
|
|
|
|
|
}
|
|
|
|
|
int main() {
|
|
|
|
|
//模拟7行7列,从(1,1)出发,开始打表,然后找规律
|
|
|
|
|
for (n = 1; n <= 7; n++)
|
|
|
|
|
for (m = 1; m <= 7; m++)
|
|
|
|
|
dfs(1, 1, 0);
|
|
|
|
|
|
|
|
|
|
//输出每个行、列情况下的摆法数量
|
|
|
|
|
for (int i = 1; i <= 7; i++) {
|
|
|
|
|
for (int j = 1; j <= 7; j++)
|
|
|
|
|
printf("%02d ", ans[i][j]);
|
|
|
|
|
puts("");
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|