AcWing
  • 首页
  • 题库
  • 题解
  • 分享
  • 问答
  • 活动
  • 应用
  • 吐槽
  • 登录/注册

AcWing 1432. 棋盘挑战 0.1 AC币

作者: 作者的头像   纳兰晚宁 ,  2021-01-23 11:51:30 ,  阅读 9


0


#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

const int N =15;
int n;
bool col[N],dg[N*2],udg[N*2];
int path[N],ans;

void dfs(int x)
{
    if(x>n)
    {
        ans++;
        if(ans<=3)
        {
            for(int i=1;i<=n;i++)
              cout<<path[i]<<' ';
            cout<<endl;
        }
        return ;
    }

    for(int y=1;y<=n;y++)
       if(!col[y]&&!dg[x+y]&&!udg[x-y+n])
       {
           path[x]=y;
           col[y]=dg[x+y]=udg[x-y+n]=true;
           dfs(x+1);
           col[y]=dg[x+y]=udg[x-y+n]=false;
           path[x]=0;
       }
}
int main()
{
    cin>>n;
    dfs(1);
    cout<<ans<<endl;
    return 0;
}

0 评论

你确定删除吗?

© 2018-2021 AcWing 版权所有  |  京ICP备17053197号-1
联系我们  |  常见问题
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息