记录编号 598546 评测结果 AAAAAAAAAA
题目名称 [USACO 1.5.4] 跳棋的挑战 最终得分 100
用户昵称 Gravatar李金泽 是否通过 通过
代码语言 C++ 运行时间 1.843 s
提交时间 2025-01-25 16:16:18 内存使用 1.53 MiB
显示代码纯文本
#include<cstdio>
#define N 14
using namespace std;
int n,ans,a[N],t[N];
void dfs(int s,int r,int z,int y)
{
    if(s==n)
    {
        ans++;
        if(ans>3)return;
        for(int i=0;i<n;i++)printf("%d ",a[i]+1);
        printf("\n");
        return;
    }
    for(int i=0;i<n;i++)
        if(!(t[i]&(r|z|y)))
        {
            a[s]=i;
            dfs(s+1,r|t[i],(z|t[i])<<1,(y|t[i])>>1);
        }
}
int main(){
    freopen("checker.in","r",stdin);freopen("checker.out","w",stdout);
    t[0]=1;for(int i=1;i<N;i++)t[i]=t[i-1]<<1;
    scanf("%d",&n);
    dfs(0,0,0,0);
    printf("%d",ans);
    return 0;
}