POJ 1321 Checkerboard Issues

Source: Internet
Author: User

Checkerboard Issues
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 28733 Accepted: 14220

Description

In a given shape of the chessboard (the shape may be irregular) on the top of the pieces, chess pieces no difference. If you need to place any of the two pieces in the same row or column in the chessboard, please program the chessboard with a given shape and size, and put all the feasible arrangement C for the K pieces.

Input

The input contains multiple sets of test data.
The first row of each set of data is two positive integers, n K, separated by a space, indicating that the chessboard will be described in a n*n matrix and the number of pieces to be placed. N <= 8, K <= N
When 1-1 indicates the end of the input.
The next n lines describe the shape of the chessboard: N characters per line, where # represents the board area. Represents an empty area (the data guarantees that no extra blank lines or blank columns appear).

Output

For each set of data, give a line of output, the output is placed in the number of programs C (Data Assurance c<2^31).

Sample Input

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

Sample Output

21st

Good question
/************************************************author:p k29created time:2015/8/19 18:14:35File name:4.c pp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 10000+10#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespacestd;BOOLcmpintAintb) {    returnA>b;}Charmp[ -][ -];intvc[Ten];intn,k,num=0;voidDfsintRowintCNT) {    if(cnt==k) {num++;return ; }    if(row>n)return ;  for(intI=1; i<=n;i++){        if(!vc[i]&&mp[row][i]=='#') {Vc[i]=1; DFS (Row+1, cnt+1); Vc[i]=0; }} DFS (row+1, CNT); return ;}intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif    //freopen ("OUT.txt", "w", stdout);     while(cin>>n>>k) {        if(n==-1&&k==-1) Break;  for(intI=1; i<=n;i++)             for(intj=1; j<=n;j++) {cin>>Mp[i][j]; } num=0;        CLE (VC); DFS (1,0); printf ("%d\n", num); }    return 0;}

POJ 1321 Checkerboard Issues

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.