@[awdrgyjilp](/space/show?uid=87040)
#1.你不会贴代码吗?
#2.程序不够简便(我提供了我的程序)
#3.这道题正解要用到位运算(我也没对,呵呵)。
#你的程序:
```
#include<bits/stdc++.h>
using namespace std;
bool h[50];
bool a[50];
bool an[50];
int w[50];
int m[50][50];
int k=0;
void dfs(int x,int t)
{
if(x==t+1)
{
k++;
for(int i=1;i<=t;i++) m[i][w[i]]=1;
printf("NO. %d\n",k);
for(int i=1;i<=t;i++)
{
for(int j=1;j<=t;j++)
printf("%d ",m[i][j]);
printf("\n");
}
return ;
}
for(int i=1;i<=t;i++)
{
if(h[i]==false&&a[i+x]==false&&an[t+i-x]==false)
{
w[x]=i;
h[i]=true;
a[i+x]=true;
an[t+i-x]=true;
dfs(x+1,t);
h[i]=false;
a[i+x]=false;
an[t+i-x]=false;
w[x]=0;
memset(m,0,sizeof m);
}
}
}
int main()
{
int n;
scanf("%d",&n);
memset(h,false,sizeof h);
memset(an,false,sizeof an);
memset(a,false,sizeof a);
dfs(1,n);
printf("%d",k);
return 0;
} //各位dalao帮我看看。。。跪谢
```
#我的程序:
```
// luogu-judger-enable-o2
#include<iostream>
#include<cstdio>
using namespace std;
char a[14+10][14+10];
int bjk[14+10],bjj[14+10],bjl[14+10];
int n,ans;
void hs(int d)
{
if(d>n)
{
ans++;
return ;
}
for(int i=1;i<=n;i++)
{
if(a[d][i]!='.'&&!bjk[i]&&!bjj[d-i+7]&&!bjl[d+i])
{
bjk[i]=bjj[d-i+7]=bjl[d+i]=1;
hs(d+1);
bjl[d+i]=bjj[d-i+7]=bjk[i]=0;
}
}
return ;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
hs(1);
cout<<ans;
}
```
by 天南地北 @ 2018-05-02 20:14:53
@[awdrgyjilp](/space/show?uid=87040) 看看写题解的各位大佬怎么做吧
by 天南地北 @ 2018-05-02 20:15:47
@[KM鹿MK](/space/show?uid=51800) +7改为+n看看
by 梦幻的笑容 @ 2018-07-14 08:54:48
@[awdrgyjilp](/space/show?uid=87040)
by wxy_god @ 2018-09-24 10:55:01