hdu 2553 N皇后问题
2016-07-12 11:16
351 查看
N皇后问题
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;
}
Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
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;
}
相关文章推荐
- 匿名管道(4种情况 )
- Android Studio 出现Don't see your Device 解决办法
- hdu 5109 Alexandra and A*B Problem(取模,枚举,数学数论)
- 动态规划的思考(1)
- Android Proguard 详解
- Deep Learning(深度学习)
- (转)TextView属性大全
- 动态规划的思考(1)
- 插入排序
- 《C++ Primer Plus》12.7 队列模拟 学习笔记
- Persistent Numbers
- AndroidStudio MacOsFM自定义快捷键
- 信息系统项目管理师考试心德
- WebView与原生交互需要重写的方法
- pat 整数分解为若干项之和
- hibernate 更新所有字段问题
- ExtJS 4.2 教程-03:使用Ext.define自定义类
- android emulator创建avd命令
- 正则化
- Group Shifted Strings