Remember the title of a pit Die (error)--hdu2553--(DFS)

Source: Internet
Author: User

, n Queen question

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 720 Accepted Submission (s): 417

Problem description placed n Queens on the N*n's checkered chessboard, making them not attack each other (that is, any 2 queens are not allowed to be in the same row, in the same column, or in a diagonal line with a 45-angle checkerboard border.)
Your task is to find out how many legal placement methods are available for a given n.
Input has several lines, one positive integer n≤10 per line, indicating the number of boards and queens, or, if n=0, the end.
Output
A number of rows, one positive integer per line, representing the number of different placements of the queen corresponding to the input row.
Sample Input
1850

Sample Output
19210

Authorcgf
Source2008 Hznu Programming Contest
Recommendlcy

A search for classic topics, special water, but pit me half a day.

Handed over three times has been overtime, but this problem really can't think of a good optimization method .... Have to sacrifice the ultimate artifact----"hit the table" .... Jersey

46ms over, sweat ..... Pit Die (false) ...

How many duplicate test data do we have?

Code

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6#include <map>7#include <iomanip>8#include <queue>9 #defineINF 0X7FFFFFFTen #defineMAXN 15 One using namespacestd; A Const Doubleeps=1e-Ten; - intRes; - intM[MAXN][MAXN]; the intN; - intXx,yy; - intNUM[MAXN]; - BOOLOkintXinty) + { -      for(intI=1; i<=n;i++){ +         if(m[x][i]&&i!=y) A             return 0; at     } -xx=x;yy=y; -      while(xx<n&&yy<N) { -xx+=1; yy+=1; -         if(M[xx][yy]) -             return 0; in     } -xx=x;yy=y; to      while(xx>1&&yy>1){ +xx-=1; yy-=1; -         if(M[xx][yy]) the             return 0; *     } $xx=x;yy=y;Panax Notoginseng      while(xx<n&&yy>1){ -xx++; yy--; the         if(M[xx][yy]) +             return 0; A     } the      while(x>1&&y<N) { +x--;y++; -         if(M[x][y]) $             return 0; $     } -     return 1; - } the voidDfsintXinty) - {Wuyi     if(ok (x, y)) { the         if(y==N) { -res++; Wu             return; -         } About          for(intI=1; i<=n;i++){ $m[i][y+1]=1; -DFS (i,y+1); -m[i][y+1]=0; -         } A     } +     Else return; the } - void Set() $ { the      for(intI=1; i<=Ten; i++){ then=i; theres=0; theDfs0,0); -num[i]=Res; in     } the } the intMain () About { the #ifndef Online_judge theFreopen ("data.in","R", stdin); the     #endif +Std::ios::sync_with_stdio (false); -Std::cin.tie (0); the     Set();Bayi      while(cin>>n&&n!=0){ the //memset (m,0,sizeof (m)); the //res=0; - //DFS (0,0); -cout<<num[n]<<Endl; the     } the}

Remember the title of a pit Die (error)--hdu2553--(DFS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.