70pts超时求助
查看原帖
70pts超时求助
565707
mediocre_楼主2022/9/1 17:34
#include<stdio.h>
const int N = 30;
int n, a[N], ans;
bool lie[N], jia[N], jian[N];
char b[N][N];
void f(register int x){
    if(x == n + 1){
        ++ans;
        return;
    }
    for(register int i = 1; i <= n; ++i){
        if(!lie[i] && !jia[x + i] && !jian[x - i + n] && b[x][i - 1] != '.'){
            a[x] = i;
            lie[i] = true;
            jia[x + i] = true;
            jian[x - i + n] = true;
            f(x + 1);
            lie[i] = false;
            jia[x + i] = false;
            jian[x - i + n] = false;
        }
    }
}
int main() {
    scanf("%d", &n);
    for (register int i = 1;i <= n;++i)scanf("%s",b[i]);
    f(1);
    printf("%d\n", ans);
	return 0;
}

提交记录

2022/9/1 17:34
加载中...