CF237D Minesweeper 1D

本文介绍了一维扫雷游戏的算法实现,通过动态规划的方法计算合法布局的数量。文章提供了详细的解题思路及代码实现。

Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares.

For example, the correct field to play looks like that: 001*2***101*. The cells that are marked with "*" contain bombs. Note that on the correct field the numbers represent the number of bombs in adjacent cells. For example, field 2* is not correct, because cell with value 2 must have two adjacent cells with bombs.

Valera wants to make a correct field to play "Minesweeper 1D". He has already painted a squared field with width of n cells, put several bombs on the field and wrote numbers into some cells. Now he wonders how many ways to fill the remaining cells with bombs and numbers are there if we should get a correct field in the end.

Input

The first line contains sequence of characters without spaces s1s2... sn (1 ≤ n ≤ 106), containing only characters "*", "?" and digits "0", "1" or "2". If character si equals "*", then the i-th cell of the field contains a bomb. If character si equals "?", then Valera hasn't yet decided what to put in the i-th cell. Character si, that is equal to a digit, represents the digit written in the i-th square.

Output

Print a single integer — the number of ways Valera can fill the empty cells and get a correct field.

As the answer can be rather large, print it modulo 1000000007 (109 + 7).

Sample test(s)
input
?01???
output
4
input
?
output
2
input
**12
output
0
input
1
output
0

题意:类似于扫雷游戏,但只有行,有些格子是已知的,有些未知,‘?’表示未知,其余为已知。'0'表示左右都没有雷,'1'表示左右一共有一个雷,'2'表示左右一共有两个雷,‘*’表示本身就是雷。问合法的情况一共有多少种?

解题思路:这似乎也是可以算作是某一类dp了吧,我已经做到过若干道类似的题了。只是暂时还没人给它取名字。状态是dp[i][j],表示i位置符合j状态的有多少种合法状况。其中0<=i<len,0<=j<4。i表示在哪一个位置上,j=0表示i位置不是雷,i+1也不是雷,j=1表示i位置不是雷,但i+1是雷,j=2表示i位置是雷,i+1位置不是雷,j=3表示i和i+1都是雷。这么四种情况。然后就根据位置上的信息进行转移。方程如下:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 1000080
#define MOD 1000000007
#define LL long long int
LL dp[maxn][4];
char str[maxn];
int main()
{
	scanf("%s",str+1);
	int len = strlen(str+1);
	dp[0][0] = dp[0][1] = 1;
	for(int i = 1;i < len;i++)
	{
		if(str[i] == '0')
			dp[i][0] = dp[i-1][0];
		if(str[i] == '1'){
			dp[i][0] = dp[i-1][2];
			dp[i][1] = dp[i-1][0];
		}
		if(str[i] == '2')
			dp[i][1] = dp[i-1][2];
		if(str[i] == '*'){
			dp[i][2] = (dp[i-1][1] + dp[i-1][3])%MOD;
			dp[i][3] = (dp[i-1][1] + dp[i-1][3])%MOD;
		}
		if(str[i] == '?'){
			dp[i][0] = (dp[i-1][0] + dp[i-1][2])%MOD;
			dp[i][1] = (dp[i-1][0] + dp[i-1][2])%MOD;
			dp[i][2] = (dp[i-1][3] + dp[i-1][1])%MOD;
			dp[i][3] = (dp[i-1][1] + dp[i-1][3])%MOD;
		}
	}
	LL ans;
	if(str[len] == '0')
		ans = dp[len-1][0];
	else if(str[len] == '1')
		ans = dp[len-1][2];
	else if(str[len] == '2')
		ans = 0;
	else if(str[len] == '*')
		ans = (dp[len-1][1] + dp[len-1][3])%MOD;
	else ans = (dp[len-1][0] + dp[len-1][1] + dp[len-1][2] + dp[len-1][3])%MOD;
	printf("%I64d\n",ans);
	return 0;
}

		

YOLOv11人物目标检测数据集 目标类别:['Persona'] 中文类别:['人物'] 训练集:1683 张 验证集:182 张 测试集:0 张 总计:1865 张 该数据集提供了data.yaml文件,内容如下: train: ../train/images val: ../valid/images test: ../test/images nc: 1 names: ['Persona'] YOLOv11城市街头与室内场景人物目标检测数据集 该数据集涵盖了城市街头、商业街区、办公场所及室内生活等多种场景中的人物目标检测,具有广泛的应用价值。通过多样的场景设置和丰富的拍摄角度,能够有效提升模型在复杂环境下的目标识别能力,为智慧城市、安防监控及人机交互等领域提供高质量的训练数据支持。 从数据分布来看,该数据集包含1683张训练集图像、182张验证集图像以及0张测试集图像,整体比例分配合理。训练集与验证集的比例约为9.25:1,能够充分满足模型训练与性能评估的需求,确保模型在不同场景下的泛化能力得到充分验证。 该数据集的标注工作严谨规范,所有图像均经过人工精确标注,每个目标都配有清晰的边界框和统一的标签“Persona”。标注过程遵循严格的标准,确保了数据的高质量和一致性,为后续的模型训练和性能优化提供了可靠的基础。 基于其多样化的场景覆盖和高质量的标注数据,该数据集可广泛应用于智慧城市管理、公共场所安防监控、智能零售分析以及家庭安防等多个领域。特别是在需要精准识别复杂环境中人物的目标检测任务中,该数据集能够显著提升模型的准确性和鲁棒性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值