题目链接
题目描述
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 continguous 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×10 grid with 5 ships. Mini Battleship is much smaller, with a grid no larger than 5×5 and possibly fewer than 5 ships. Bob wonders how many ship placements are possible on Alice’s board given what he knows so far.
The answer will be 0 if Alice is cheating! (Or, if the game setup isn’t possible.)
输入
The first line of input contains two space-separated integers n (1 ≤ n ≤ 5) and k (1 ≤ k ≤ 5),which represent a game of Mini Battleship played on an n×n grid with k ships.
Each of the next n lines contains a string s (|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 k lines contains a single integer x (1 ≤ x ≤ n). These are the sizes of the ships.
输出
Output a single integer, which is the number of ways the k distinct ships could be placed on Alice’s grid and be consistent with what Bob sees.
样例输入 Copy
【样例1】
【样例2】
【样例3】
样例输出 Copy
【样例1】
【样例2】
【样例3】
题意:
给定一个的矩阵,其中在上一定不可以放置船,而在上面一定要放置船,在上面可以放置船,也可以不放,问将以下艘船,大小均为,放置在矩阵中的方案数量
思路:
类似经典的八皇后问题,
首先将所有的m个都成功放置之后,并且所有的O均已成功放置船艘,此时的方案书就应该 + 1
注意船的形状一共有两种情况:横着和竖着,但是对于1 * 1的情况来说就只有一种状态,这里要特判掉
我们用函数来判断是否能够是否可以放置该船,如果说要是放置过程中遇到了’X’,那是一定不能够放下去的,反之可以放下这艘船,对于能够放下去的船,我们将它的位置vis[i][j] += 1;