Nightmare


私信TA

用户名:uq_70103011803

访问量:1752

签 名:

等  级
排  名 26728
经  验 519
参赛次数 1
文章发表 6
年  龄 21
在职情况 学生
学  校 贵州商学院
专  业 物联网工程

  自我简介:

解题思路:

注意事项:

参考代码:

#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;
int white[9]={0};
int black[9]={0};
int qu[9][9]={0};
int n,count=0;
int whitequene(int x){
 if(x>n){
  count++;
  return 0;
 }
 for(int k=1;k<=n;k++){
  if(!qu[x][k]||k==black[x]){
  continue;
 }
 int j=1;
 while(j<x){
  if(white[j] == k || fabs(j - x) == fabs(white[j] - k)){
   break;
  }
  j++;
 }
 if(j==x){
  white[x]=k;
  whitequene(x+1);
 }
}
return 0;
}
int blackquene(int x){
 if(x>n){
  whitequene(1);
  return 0;
 }
 for(int k=1;k<=n;k++){
  if(!qu[x][k]){
   continue;
  }
  int j=1;
  while(j<x){
   if(black[j]==k||fabs(x-j)==fabs(k-black[j])){
    break;
   }
   j++;
  }
  if(j==x){
   black[x]=k;
   blackquene(x+1);
  }
 }
 return 0;
}
int main(){
 cin>>n;
 for(int i=1;i<=n;i++){
  for(int j=1;j<=n;j++){
   int t;
   cin>>t;
   qu[i][j]=t;
  }
 }
 blackquene(1);
 cout<<count;
 return 0;
}

 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区