Checkerboard Problem poj1321

Source: Internet
Author: User

The problem is simple DFS, yes, I did it for one hours.

The problem is given a chessboard, which. is blank, can not play chess pieces, #是可以放棋子的位置. When placing a piece, only one pawn can be placed in the same row.

Input N,k

Then enter the N*n board, #或者. , how many ways to put the pieces.

·· DFS (S,KK) indicates how many pieces have been placed in the first line.

Of course, starting with DFS (0,0).

Initially DFS (I+1,KK++1) was written as DFS (s+1,kk+1), and then always tle.

1#include <cstdio>2#include <cstring>3 Charmap[Ten][Ten];4 BOOLvis[Ten];5 intAns,k,n;6 voidDFS (intSintKK)7 {8     if(kk==k) {9ans++;Ten         return ; One     } A      for(inti=s;i<n;i++){ -          for(intj=0; j<n;j++){ -             if(!vis[j]&&map[i][j]=='#'){ thevis[j]=true; -DFS (i+1, kk+1); -vis[j]=false; -             } +         } -     } + } A intMain () at { -      while(SCANF ("%d%d",&n,&k)) { -         if(n==-1&&k==-1) -              Break; -          for(intI=0; i<n;i++) -scanf"%s", Map[i]); inmemset (Vis,false,sizeof(Vis)); -ans=0; toDFS (0,0); +printf"%d\n", ans); -     } the     return 0; *}
View Code

Checkerboard Problem poj1321

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.