mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-28 18:41:38 +08:00
53 lines
2.4 KiB
HTML
53 lines
2.4 KiB
HTML
<!DOCTYPE html>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<h1>1019. Separate the Animals (35)</h1>
|
|
<div id="problemContent">
|
|
<p>There are some animals in a zoo which can be described as a grid with N rows and M columns. Your task is to place some obstacles so that no pairs of animals can reach each other.
|
|
</p>
|
|
<p>
|
|
Two animals can <b>reach each other</b> if and only if their cells are <b>4-connected</b>. For example, in Figure 1, the central blue cell can be reached by the four red cells, and cannot be reached by the other four white cells.
|
|
</p>
|
|
<center><img src="http://nos.patest.cn/pe_ovw14g1rloy.JPG"/><br/>Figure 1</center>
|
|
<p>
|
|
What is more, you must put obstacles in exactly K cells, which are 4-connected and form exactly H holes. Here a <b>hole</b> is defined as a 4-connected part with finitely many open cells while the zoo is placed in an infinite open grid. For example, there are 2 holes (the green and the yellow areas) in Figure 2.
|
|
</p>
|
|
<center><img src="http://nos.patest.cn/pe_ovw14ksk9ux.JPG"/><br/>Figure 2</center>
|
|
<p>
|
|
For the following grid with two animals:
|
|
</p>
|
|
<center><img src="http://nos.patest.cn/pe_ovw1511p3u3.jpg"/><br/>Figure 3</center>
|
|
<p>
|
|
If K = 8 and H = 1, one way to separate them is the following:
|
|
</p>
|
|
<center><img src="http://nos.patest.cn/pe_ovw15u5uah0.jpg"/><br/>Figure 4</center>
|
|
<p>
|
|
Figure 5 is illegal because it contains no hole.
|
|
</p>
|
|
<center><img src="http://nos.patest.cn/pe_ovw1bm9izxb.jpg"/><br/>Figure 5</center>
|
|
<p>
|
|
Figure 6 is also illegal because the obstacles are not 4-connected.
|
|
</p>
|
|
<center><img src="http://nos.patest.cn/pe_ovw1c4ccr11.jpg"/><br/>Figure 6</center>
|
|
<p>
|
|
Given some animals, you are supposed to count the number of different solutions.
|
|
</p>
|
|
<p><b>
|
|
Input Specification:
|
|
</b></p>
|
|
<p>Each input file contains one test case. For each case, the first line gives four integers: N, M, K, H (2 <= N, M <= 6; 1 <= K <= 12; 0 <= H <= 2). All the numbers are separated by spaces.</p>
|
|
<p>Then N lines follow, each contains M characters, which are either "." or "O", representing an open cell or an animal, respectively. There will be at least 2 animals.
|
|
</p>
|
|
<p><b>
|
|
Output Specification:
|
|
</b></p>
|
|
<p>For each case, print a single line containing a single integer: the number of solutions.</p>
|
|
<b>Sample Input:</b><pre>
|
|
3 5 8 1
|
|
...O.
|
|
.O...
|
|
.....
|
|
</pre>
|
|
<b>Sample Output:</b><pre>
|
|
8
|
|
</pre>
|
|
</div> |