usaco checker

来源:互联网 发布:淘宝怎么设置上新提醒 编辑:程序博客网 时间:2024/06/06 05:03
/*ID: ljracm1LANG: C++PROB: checker*/#include<cstdio>#define Tint n,t;int col[15];int dig1[40],dig2[40];int row[15];void dfs(int d){    if(d>n){        t++;        if(t<=3){            for(int i=1; i<=n; i++)                printf("%d%c",row[i],i==n?'\n':' ');        }    }    for(int i=1; i<=n; i++){        if(!col[i]&&!dig1[i+d]&&!dig2[d+(n+1-i)]){             col[i]=1;             dig1[i+d]=1;             dig2[d+(n+1-i)]=1;             row[d]=i;             dfs(d+1);             col[i]=0;             dig1[i+d]=0;             dig2[d+(n+1-i)]=0;        }    }}int main(){    #ifdef T        freopen("checker.in","r",stdin);        freopen("checker.out","w",stdout);    #endif    scanf("%d",&n);    t=0;    dfs(1);    printf("%d\n",t);    return 0;}

0 0
原创粉丝点击