当前位置:网站首页>7-1 n queen problem
7-1 n queen problem
2022-06-26 13:21:00 【White -】
7-1 n queens problem
Ask for in n*n The chessboard of the grid will not attack each other n A queen . According to the rules of chess , The queen can attack the pieces on the same row, column or diagonal line .
Input format :
There are multiple sets of test data , Processing to the end of the file . For each group of tests , Enter the size of the chessboard n(1<n<12).
Output format :
For each group of tests , Output the number of schemes that meet the requirements .
sample input :
4
sample output :
2
Code :
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int n,a[200],plan;
void dfs(int x){
if(x>n){
plan++;
return;
}
for(int i=1;i<=n;i++){
a[x]=i;
int flag=0;
for(int j=1;j<=x-1;j++){
if(a[x] == a[j] || fabs(x-j)==fabs(a[x]-a[j])){
flag=1;
break;
}
}
if(flag==0)
dfs(x+1);
}
}
int main()
{
while(scanf("%d",&n)!=EOF){
plan=0;
for(int i=1;i<20;i++)
a[i]=0;
dfs(1);
cout<<plan<<endl;
}
return 0;
}
202206260908 Japan
边栏推荐
- Electron official docs series: Distribution
- MariaDB study notes
- Some conclusions about Nan
- 外观模式(Facade)
- [how to connect the network] Chapter 2 (next): receiving a network packet
- Typescript
- KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
- Zoomeeper sets ACL permission control (only specific IP access is allowed to enhance security)
- 防火墙介绍
- Go structure method
猜你喜欢

Learn how to develop owl components by hand (7): practical use of owl projects

MySQL讲解(二)

首批通过!百度智能云曦灵平台获信通院数字人能力评测权威认证

Chapter 10 setting up structured logging (2)

外观模式(Facade)

Opencv high speed download

Log in to the server using SSH key pair

ES6 module

Processsing function random

IDC report: the AI cloud market share of Baidu AI Cloud ranks first for six consecutive times
随机推荐
MediaPipe手势(Hands)
What features are added to Photoshop 2022 23.4.1? Do you know anything
Sinotech software outsourcing
awk工具
原型模式(prototype)
Bridge mode
A few lines of code can realize complex excel import and export. This tool class is really powerful!
Do you know the limitations of automated testing?
Word document export (using fixed template)
Script - crawl the customized storage path of the cartoon and download it to the local
Beifu PLC realizes data power-off maintenance based on cx5130
Arcpy——InsertLayer()函數的使用:摻入圖層到地圖文檔裏
HDU 5860
HDU 3709 Balanced Number
Solutions to insufficient display permissions of find and Du -sh
What are the common categories of software testing?
Opencv high speed download
I - Dollar Dayz
Bigint: handles large numbers (integers of any length)
POJ 3070 Fibonacci