hdu 2553 N皇后问题

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

 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[n]<<endl;
    }
    return 0;
}



posted on 2016-07-12 11:16  胖胖的乓乓  阅读(131)  评论(0编辑  收藏  举报

导航