#P15996. [ICPC 2020 NAC] Mini Battleship

[ICPC 2020 NAC] Mini Battleship

题目描述

Battleship is a game played by two players. Each player has their own grid, which is hidden from their opponent. Each player secretly places some ships on their grid. Each ship covers a horizontal or vertical straight line of one or more contiguous squares. Ships cannot overlap. All ships are considered distinct, even if they have the same size.

After placing their ships, the players then take turns taking shots at their opponent’s ships by calling out a coordinate of their opponent’s grid. The opponent must honestly say whether the shot was a hit or a miss. When all of a ship’s squares are hit, that ship sinks (“You sunk my battleship!!”). A player loses when all of their ships are sunk.

Bob is playing a game of Mini Battleship against Alice. Regular Battleship is played on a 10×1010 \times 10 grid with 55 ships. Mini Battleship is much smaller, with a grid no larger than 5×55 \times 5 and possibly fewer than 55 ships.

Bob wonders how many ship placements are possible on Alice’s board given what he knows so far. The answer will be 00 if Alice is cheating! (Or, if the game setup isn’t possible.)

输入格式

The first line of input contains two space-separated integers nn (1n51 \le n \le 5) and kk (1k51 \le k \le 5), which represent a game of Mini Battleship played on an n×nn \times n grid with kk ships.

Each of the next nn lines contains a string ss (s=n|s| = n). This is what Bob sees of Alice’s grid so far.

  • A character ‘X’ represents one of Bob’s shots that missed.
  • A character ‘O’ (Letter O, not zero) represents one of Bob’s shots that hit.
  • A Dot (‘.’) represents a square where Bob has not yet taken a shot.

Each of the next kk lines contains a single integer xx (1xn1 \le x \le n). These are the sizes of the ships.

输出格式

Output a single integer, which is the number of ways the kk distinct ships could be placed on Alice’s grid and be consistent with what Bob sees.

4 3
....
.OX.
....
O..X
3
2
1
132
4 4
.X.X
.XX.
...X
....
1
2
3
4
6
2 2
..
..
2
2
4