Score : $500$ points
You are given a grid with $N$ rows and $N$ columns, where the square at the $i$-th row from the top and $j$-th column from the left is painted black if $S_{i, j}$ is #
and white if $S_{i, j}$ is .
.
You will choose $K$ of the white squares and paint them red. How many such ways to paint the grid satisfy the following condition?
#
or .
.Input is given from Standard Input in the following format:
$N$ $K$ $S_{1, 1}S_{1, 2} \dots S_{1, N}$ $S_{2, 1}S_{2, 2} \dots S_{2, N}$ $\vdots$ $S_{N, 1}S_{N, 2} \dots S_{N, N}$
Print the answer.
3 5 #.# ... ..#
5
We have five ways to satisfy the condition as shown below, where @
stands for a red square.
#.# #@# #@# #@# #@# @@@ .@@ @@. @@@ @@@ @@# @@# @@# .@# @.#
Note that the way shown below does not satisfy the connectivity requirement since we do not consider diagonal adjacency.
#@# @.@ @@#
2 2 #. .#
0
There is no way to satisfy the condition.
8 8 ........ ........ ........ ........ ........ ........ ........ ........
64678