24分,对照打标的都对,哪错了

P1219 [USACO1.5] 八皇后 Checker Challenge

haluyaoac @ 2024-10-06 12:04:58

#include<iostream>
using namespace std;

int ct=0,n,is_visit[3][15]={0},ans[15];

void dfs(int cur){
    if(cur==n){
        if(ct<3){
            for(int i=0;i<n;i++){
                cout<<ans[i]<<" ";
                //else cout<<' '<<ans[i];
            }
            cout<<endl;
        }
        ct++;
        return;

    }
    for(int i=0;i<n;i++){
        if(!is_visit[0][i]&&!is_visit[1][i+cur]&&!is_visit[2][cur-i+n]){
            ans[cur]=i+1;
            is_visit[0][i]=is_visit[1][cur+i]=is_visit[2][cur-i+n]=1;
            dfs(cur+1);
            is_visit[0][i]=is_visit[1][cur+i]=is_visit[2][cur-i+n]=0;
        }
    }
    return;
}

int main(){
    cin>>n;
    dfs(0);
    cout<<ct;
    return 0;
}

by haluyaoac @ 2024-10-06 12:05:42

说错了,大表


by haluyaoac @ 2024-10-06 12:06:14

@haluyaoac 打表


by A_sh @ 2024-10-15 09:23:16

int is_visit[3][15]={0},ans[15];

数组开小了,到30就能过了


|