Hpoj 1698: Sea, Iceberg, battleship "DFS"

Source: Internet
Author: User

1698: Sea, Iceberg, battleship time limit: 1 Sec memory limit: MB
submitted: 5 Resolution:
Submitted State [Discussion Version] Title Description

Give an n * N of the ocean, #代表海域,. To place a k battleship in the sea, the battleship will attack other warships in the same row, so the same row cannot be placed on the other battleship, asking how many (data guaranteed c<2^31) The plan number C is.

Input

The input contains multiple sets of test data.
The first row of each set of data is two positive integers, n K, (n <= 8, K <= N)

The following n lines describe the shape of the ocean: each row has n characters, where # represents the sea area. Represents an iceberg

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...#. #.. #.. #...
Sample output
A similar to the N Queen question ~
Ac-code:
#include <cstdio> #include <cstring>int k,m,sum,vis[10];char s[10][10];void dfs (int row,int num) {if (num==k ) Sum++;else if (row==m) return, else{for (int i=0;i<m;i++) {if (!vis[i]&&s[row][i]== ' # ') {Vis[i]=1;dfs (row+1 , num+1); vis[i]=0;}} DFS (Row+1,num);}} int main () {int i;while (~scanf ("%d%d", &m,&k)) {for (i=0;i<m;i++) scanf ("%s", S[i]); Memset (Vis ); Sum=0;dfs (0,0);p rintf ("%d\n", sum);} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hpoj 1698: Sea, Iceberg, battleship "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.