D. Minesweeper 1D
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

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.

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
Note

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的更多相关文章

  1. cf div2 234 D

    D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. 离线dfs CF div2 707 D

    http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...

  3. cf div2 239 D

    D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. cf div2 236 D

    D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. cf div2 238 D

    D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  6. cf div2 238 c

    C. Unusual Product time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. cf div2 235 D

    D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...

  8. cf div2 234 E

    E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...

  9. CF div2 D BFS

    http://codeforces.com/contest/676/problem/D 题目大意: 勇者去迷宫杀恶龙.迷宫是有n*m的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...

随机推荐

  1. linux 病毒 sfewfesfs

    由于昨天在内网服务器A不小心rm -fr / ,导致服务器A完蛋,重装系统后,不知道啥原因,局域网瘫痪不能上网,最后发现内网服务器A的一个进程sfewfesfs cpu 300%.路由器被网络阻塞啦. ...

  2. hdu 1053 Entropy

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1053 Entropy Description An entropy encoder is a data ...

  3. C#之玩转反射【转:http://www.cnblogs.com/yaozhenfa/p/CSharp_Reflection_1.html】

    前言 之所以要写这篇关于C#反射的随笔,起因有两个:   第一个是自己开发的网站需要用到   其次就是没看到这方面比较好的文章. 所以下定决心自己写一篇,废话不多说开始进入正题. 前期准备 在VS20 ...

  4. Android实现SQLite数据库联系人列表

    Android实现SQLite数据库联系人列表 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个通讯录查看程序: 要求使用SQLite ...

  5. cocos2dx中使用声音引擎需要包含的头文件

    1.需要包含的头文件和命名空间 #include "SimpleAudioEngine.h"using namespace CocosDenshion;

  6. gitlab&fengoffice的ldap配置

    1.fengoffice配置config/ldap_config.php $config_ldap = array ( 'binddn' => 'cn=admin,dc=xxx,dc=xxx', ...

  7. 创建ubuntu软件源

    缘起:虚拟机需要安装一些文件,但是直接从外网下载比较慢,而且安装iso包中是有这些软件的,所以创建一个ubuntu  apt server ubuntu 12.04, 本机192.168.0.124, ...

  8. 国内最快的jquery cdn

    cdnjs.cn是cdnjs.com在国内的镜像服务,项目托管与著名的又拍云存储,目前又拍云在全国有几十个cdn节点,并且还在增加中. cdnjs.cn 托管的jquery相信会成为国内最快的jque ...

  9. Careercup - Google面试题 - 5085331422445568

    2014-05-08 23:45 题目链接 原题: How would you use Dijkstra's algorithm to solve travel salesman problem, w ...

  10. 项目部署之VPN+端口映射

    背景:出差开发项目,需要在客户那里部署基本成型的系统.这套系统需要一个公网的ip地址(一个后台管理系统,使用花生壳提供域名服务.一个公网的tcp server,java io实现),但是客户那里无法提 ...