cf div2 237 D
2 seconds
512 megabytes
standard input
standard output
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.
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.
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).
?01???
4
?
2
**12
0
1
0
In the first test sample you can get the following correct fields: 001**1, 001***, 001*2*, 001*10.
DP 给5种情况进行编号,0代表当前位置是0,1代表当前位置是1且左边有炸弹,2代表当前位置是1左边没有炸弹,3代表当前位置是2,4代表当前位置是炸弹
dp2[0] = dp1[0];
dp2[1] = dp1[4];
dp2[2] = dp1[0] + dp1[1] ;
dp2[3] = dp1[4];
dp2[4] = dp1[4] + dp1[2] + dp1[3];
注意边界和数据范围即可。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; typedef long long ll; #define maxn 1000005
#define MOD 1000000007 char s[maxn];
int dp[][];
void solve() { int *dp1 = dp[],*dp2 = dp[];
dp1[] = strlen(s) != && (s[] == '' || s[] == '?');
dp1[] = s[] == '' || s[] == '?';
dp1[] = s[] == '*' || s[] == '?';
for(int i = ; i < strlen(s); ++i) {
if(s[i] == '?' || s[i] == '') {
if(i != strlen(s) - )
dp2[] = (dp1[] + dp1[]) % MOD;
dp2[] = dp1[];
}
if(s[i] == '?' || s[i] == '') {
if(i != strlen(s) - )
dp2[] = dp1[];
}
if(s[i] == '?' || s[i] == '') {
dp2[] = (dp1[] + dp1[]) % MOD;
}
if(s[i] == '?' || s[i] == '*') { dp2[] = ((ll)dp1[] + dp1[] + dp1[]) % MOD;
} swap(dp1,dp2);
for(int j = ; j <= ; ++j) dp2[j] = ;
} int ans = ;
for(int i = ; i <= ; ++i) { ans = (ans + dp1[i]) % MOD;
} printf("%d\n",ans);
} int main() {
//freopen("sw.in","r",stdin); scanf("%s",s); solve(); return ;
}
cf div2 237 D的更多相关文章
- cf div2 234 D
D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 离线dfs CF div2 707 D
http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...
- cf div2 239 D
D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- cf div2 236 D
D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 238 D
D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- cf div2 238 c
C. Unusual Product time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 235 D
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- cf div2 234 E
E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
- CF div2 D BFS
http://codeforces.com/contest/676/problem/D 题目大意: 勇者去迷宫杀恶龙.迷宫是有n*m的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...
随机推荐
- Java生成唯一的ID
public class UIDGenerator { private static Date date = new Date(); private static StringBuilder buf ...
- Lex+YACC详解
1. 简介 只要你在Unix环境中写过程序,你必定会邂逅神秘的Lex&YACC,就如GNU/Linux用户所熟知的Flex&Bison,这里的Flex就是由Vern Paxon实现的一 ...
- hdu 4308 Saving Princess claire_
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...
- 魔兽世界私服Trinity,从源码开始
缘起因由 在一个无所事事的周末下午,突然想起魔兽世界,官方的账号很久没有上了,里面的大小号现在连满级都不是.以前曾经搭过传奇和星际争霸战网的私服自娱自乐,也听说过魔兽世界有开源的服务端模拟,既然兴致来 ...
- (转)redis 学习笔记(1)-编译、启动、停止
redis 学习笔记(1)-编译.启动.停止 一.下载.编译 redis是以源码方式发行的,先下载源码,然后在linux下编译 1.1 http://www.redis.io/download 先 ...
- asp.net mvc 错误路由默认配置
问题描述:默认情况下mvc已经将路由参数设置配置好了,这里就不在讲解,请到园子搜索,有很多这方面相关的文章.这里讲述的是,一个MVC项目中,我们输入一个错误的URL,或者根本不存在的URL,如:htt ...
- 一样的Android,不一样的学习
这几年,Android开始慢慢流行起来,很多项目也开始涉及这部分内容,所以学习Android也就变的很有意义了. 学什么 学习Android应该学什么,很多人有不同的见解.一般程序员可能只是学习And ...
- C++变量的存储类别与作用域
总结一下C++中变量的存储类别以及变量的作用域. (1)标示符的存储类别决定了标示符在内存中存在的时间(我们可以理解标示符就是确定一个变量的符号,也就是我们所说的变量名) 二:存储类别 (1)静态存储 ...
- CentOS安装Git实现多人同步开发
描 述 要开发一个"cms系统",有2个人分别是:晓飞, 盈月.要求使用Git来进行版本控制. 项目信息 版本控制:Git 项目名称:cms 开发人员:xiaofei,yingyu ...
- PBOC2.0与PBOC3.0的区别
2013年2月,中国人民银行发布了<中国金融集成电路(IC)卡规范(V3.0)>(以下简称PBOC3.0),PBOC3.0是在中国人民银行2005年颁布的<中国金融集成电路(IC)卡 ...