您的位置:首页 > 其它

hdu 2553 N皇后问题

2016-07-12 11:16 351 查看
N皇后问题

Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u
Submit Status

Description

在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 

你的任务是,对于给定的N,求出有多少种合法的放置方法。 

 

Input

共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。
 

Output

共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。
 

Sample Input

1
8
5
0

 

Sample Output

1
92
10

 

N皇后问题

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int n;
int vis[3][100];
int ans;
int a[]={0,1,0,0,2,10,4,40,92,352,724};
int main()
{
while(~scanf("%d",&n) && n)
{
cout<<a
<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: