杭电 2553 N皇后问题
来源:互联网 发布:minecraft 下载 编程 编辑:程序博客网 时间:2024/05/16 07:07
N皇后问题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): Accepted Submission(s):
Problem Description
在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。
你的任务是,对于给定的N,求出有多少种合法的放置方法。
你的任务是,对于给定的N,求出有多少种合法的放置方法。
Input
共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。
Output
共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。
Sample Input
1850
Sample Output
1
92
10
n皇后问题,不知道怎么,深搜回溯还是会超时,打表有时是很吊的!
1
92
10
n皇后问题,不知道怎么,深搜回溯还是会超时,打表有时是很吊的!
/*#include <stdio.h>#include <string.h>#include<math.h>#define N 20int n,s,a,l[N];int kefang(int a){ int j; for(j=1;j<a;j++) if(fabs(l[a]-l[j])==fabs(a-j)||l[a]==l[j]) return 0; return 1;}int xiaqi(int a){ int i; if(a>n&&n>0) s++; else{ for(i=1;i<=n;i++) { l[a]=i; if(kefang(a)) xiaqi(a+1); } } return s;}int main(){ while(~scanf("%d",&n)&&n) { int num; s=0; num=xiaqi(1); printf("%d\n",num); } return 0;}*/#include<iostream>using namespace std;int main(){ int n; int a[11]={0,1,0,0,2,10,4,40,92,352,724}; while(cin>>n) { if(n==0) break; cout<<a[n]<<endl; } return 0;}
2 0
- 杭电 2553 N皇后问题
- 杭电 2553 N皇后问题
- 杭电2553 N皇后问题
- 杭电2553N皇后问题(dfs)
- 【杭电】[2553]N皇后问题
- 杭电 2553 N皇后问题
- 杭电--2553 N皇后问题
- 【杭电2553】N皇后
- HDOJ 2553 N皇后问题 杭电 ACM
- 杭电2553--N皇后问题(回溯)
- N皇后问题 HDU 杭电2553【递归回溯】
- 杭电-2553 N皇后问题 (经典深搜)
- 杭电 2533 N皇后问题
- 杭电hdu N皇后问题
- 杭电 hdu 2553. N皇后问题
- 杭电 hdu 2553 N皇后
- 杭电-N皇后问题(经典DFS搜索)
- 杭电2553 N皇后问题(普通方法和位运算两种方法)
- 位图索引(Bitmap Index)
- (1)顺序线性表(Java)
- 函数索引使用之部分记录建索引
- Uncaught Error: Bootstrap's JavaScript requires jQuery
- where would you go this weekend?...
- 杭电 2553 N皇后问题
- JavaWeb入门实战—EL表达式&JSTL标签
- 第4周作业-打字成绩判断程序
- where would you go this weekend?(2013.10.20)
- 环境搭建
- php case语句 分号
- 递归法逆序输出字符串
- Android 录音机模块分析
- ffmpeg参数说明