Poj 1321 board problem search

Source: Internet
Author: User

Board Problems
Time limit:1000 ms   Memory limit:10000 K
Total submissions:22144   Accepted:10988

Description

There is no difference in placing a piece on a given-shape chessboard (which may be irregular. It is required that any two chess pieces should not be placed in the same row or column of the board. Please program to solve all feasible placement schemes C for all K chess pieces with a given shape and size.

Input

The input contains multiple groups of test data.
The first row of each group of data is two positive integers, n k, separated by a space, indicating that the board will be described in an N * n matrix, and the number of pieces placed. N <= 8, k <= N
If it is-1-1, the input ends.
The next n lines describe the shape of the Board: each line has n characters, where # indicates the board area, and .. indicates the blank area (no extra blank rows or columns are required for data ).

Output

For each group of data, a single line of output is provided, and the number of solutions placed in the output is C (Data guarantee is C <2 ^ 31 ).

Sample Input

 
2 1 #... #4 4... #-1-1

Sample output

 
21



 
# Include <iostream> # include <cstring> using namespace STD; int n, m, ans; int V [10]; char C [10] [10]; void DFS (int r, int K) {int I, j; If (k = m) ans ++; else for (I = R + 1; I <N; I ++) for (j = 0; j <n; j ++) if (C [I] [J] = '#'&&! V [J]) {v [J] = 1; DFS (I, k + 1); V [J] = 0 ;}} int main () {While (CIN> N> m) {memset (v, 0, sizeof (v); If (n =-1 & M =-1) break; int I; for (I = 0; I <n; I ++) scanf ("% s", C [I]); ans = 0; DFS (-1, 0); cout <ans <Endl;} return 0 ;}


Poj 1321 board problem search

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.