B - Mini Battleship Kattis - minibattleship

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. The orientation of each ship is not important to the game, only the squares they occupy.

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 \! 1010×10 grid with 555 ships. Mini Battleship is much smaller, with a grid no larger than 5 ⁣× ⁣55 \! \times \! 55×5 and possibly fewer than 555 ships.

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

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

Each of the next nnn lines contains a string sss (∣s∣=n|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 kkk lines contains a single integer xxx (1≤x≤n1 \le x \le n1≤x≤n). These are the sizes of the ships.
Output

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

4 3
....
.OX.
....
O..X
3
2
1

	

132

Sample Input 2 	Sample Output 2

4 4
.X.X
.XX.
...X
....
1
2
3
4

	

6

Sample Input 3 	Sample Output 3

2 2
..
..
2
2

	

4

Sponsor

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
typedef long long LL;
using namespace std;
int n,k,ans; 
char s[100][100]; 
int kk[100]; 
int m[100][100];
void dfs(int x)
{
    
//   cout<<"djheje"<<endl;
//	printf("now search %d\n",x);  
//   cout<<ans<<endl; 
//	if(x>k) return;
	if(x>k)
	{
   
		for(int i=1;i<=n;i++)
		{
   
			for(int j=1 ;j<=n ;j++)
			{
   
				if(s[i][j-1]=='O'&&m[i][j]==0)//?
				return; 
			}
		}
	    ans++; 
	    return; 
	}
	int len =kk[x]; 
	for(int i =1 ;i<=n ;i++)
	{
   
		int f= 0; 
		for(int j =1; j<= n ;j++)
		{
   
			if(m[i][j]==0)
			{
   
				f++; 
				if(f==len)
				{
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值