记录编号 603263 评测结果 AAAAAAAAAA
题目名称 64.[USACO 1.5.4] 跳棋的挑战 最终得分 100
用户昵称 Gravatar2_16鸡扒拌面 是否通过 通过
代码语言 C++ 运行时间 0.768 s
提交时间 2025-07-10 10:42:03 内存使用 3.67 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
unsigned ans=0,n,s[15]={0},upperlim=1;
//syzx王国正老师讲课版本 
void queens_dfs(unsigned row,unsigned ld,unsigned rd,unsigned i)
{
    if(i>n)
    {
        ans++;
        if(ans<=3)
        {
            for(int i=1;i<=n;i++) cout<<s[i]<<" ";
            cout<<endl;
        }
    }
    else
    {
        int pos=(~(row|ld|rd))&upperlim;
        while(pos>0)
        {
            int p=pos&(pos*(-1));
            if(ans<=3)
            {
                int k=p,x=0;
                while(k!=0)
                {
                    k=k>>1;
                    x++;
                }
                s[i]=x;
            }
            pos-=p;
            queens_dfs(row+p,(ld+p)<<1,(rd+p)>>1,i+1);
        }
    }
}
int main(){
    freopen("checker.in","r",stdin);
    freopen("checker.out","w",stdout);
    cin>>n;
    upperlim=(upperlim<<n)-1;
    queens_dfs(0,0,0,1);
    cout<<ans;
    return 0;
}