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的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...
随机推荐
- 成功完成Moses Manual中BaseLineSystem
终于把这个破法语句子翻译出来了,各种耗时,bug,弄了一天,明天争取看完详细的翻译教程! 而且还要学习中文分词,晚安,Moses!
- Linux中printf格式化输出
printf使用文本或者由空格分隔的参数,我们可以在printf中使用格式化字符串.printf不会写像echo那样自动添加换行符,必须手动添加 =========================== ...
- Python 爬虫实例
下面是我写的一个简单爬虫实例 1.定义函数读取html网页的源代码 2.从源代码通过正则表达式挑选出自己需要获取的内容 3.序列中的htm依次写到d盘 #!/usr/bin/python import ...
- Android 实现子View的状态跟随父容器的状态
最近自学着做东西,需要做一个效果,就是我ListView的Item点击下或者选中的时候,我Item里面的各个组件的状态要和我Item的状态保持一直,这样我就可以用XML,去根据组件的不同状态去实现不同 ...
- CoverFlow效果
1. 成员函数 mCamera是用来做类3D效果处理,比如z轴方向上的平移,绕y轴的旋转等 mMaxRotationAngle是图片绕y轴最大旋转角度,也就是屏幕最边上那两张图片的旋转角度 mMaxZ ...
- orcherd 汉化
点击这里下载汉化包,此汉化包是在是在前人的基础上精心整理修改的,后续汉化版本随时升级更新. Orchard汉化包 下载后解压缩后打开后看到如下文件夹(App_Data.Core.Modules.The ...
- iOS学习之UIView
一.UI编程概述 1.UI的本意是用户界面,是英文User和Interface的缩写. 2.UI设计则是指对软件的人机交互.操作逻辑.界面美观的整体设计. 3.软件设计可 ...
- MVC4.0 WebApi如何自定义返回数据类型
1.客户端可以通过HTTP Accept消息头来通知服务器客户端想要什么样的MIME类型数据,例如:application/json则代表告诉服务器想要的是Json数据 2.服务器端撇开客户端的请求类 ...
- Qt中的事件
1. 引自---http://blog.sina.com.cn/s/blog_6e80f1390100pro4.html 信号和事件的区别就在与,事件比信号更加底层,而且如果一个信号对应多个槽的话,信 ...
- Web中Listener的创建
使用Listener只需要两个步骤: 定义Listener实现类. 通过Annotation或在web.xml文件中配置Listener 实现Listener类 监听不同Web事件的监听器不相同,常用 ...