cf404D Minesweeper 1D 状态转移dp
来源:互联网 发布:官方软件 编辑:程序博客网 时间:2024/06/09 20:59
Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width isn 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, field2* 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 ofn 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 thei-th cell of the field contains a bomb. If charactersi equals "?", then Valera hasn't yet decided what to put in thei-th cell. Character si, that is equal to a digit, represents the digit written in thei-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).
#define DeBUG#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <string>#include <set>#include <sstream>#include <map>#include <bitset>using namespace std ;#define zero {0}#define INF 2000000000#define EPS 1e-6typedef long long LL;const double PI = acos(-1.0);//#pragma comment(linker, "/STACK:102400000,102400000")inline int sgn(double x){ return fabs(x) < EPS ? 0 : (x < 0 ? -1 : 1);}const int mod = 1000000007;long long dp[1000005][5] = zero;char s[1000005];/*0 这位置为01 这位置为1且左边是雷2 这位置为1且右边是雷3 这位置为24 这位置为雷*/int main(){#ifdef DeBUGs freopen("//home//amb//桌面//1.in", "r", stdin);#endif while (scanf("%s", s) + 1) { memset(dp, 0, sizeof(dp)); int l = strlen(s); if (s[0] == '0') { dp[0][0] = 1; } else if (s[0] == '1') { dp[0][2] = 1; } else if (s[0] == '2') { printf("0\n"); continue; } else if (s[0] == '*') { dp[0][4] = 1; } else dp[0][0] = dp[0][2] = dp[0][4] = 1; for (int i = 1; i < l; i++) { if (s[i] == '0' || s[i] == '?') { dp[i][0] = (dp[i - 1][1] + dp[i - 1][0]) % mod; } if (s[i] == '1' || s[i] == '?') { dp[i][1] = dp[i - 1][4]; dp[i][2] = (dp[i - 1][0] + dp[i - 1][1]) % mod; } if (s[i] == '2' || s[i] == '?') { dp[i][3] = dp[i - 1][4]; } if (s[i] == '*' || s[i] == '?') { dp[i][4] = (dp[i - 1][2] + dp[i - 1][3] + dp[i - 1][4]) % mod; } } // for (int i = 0; i <l; i++) // { // printf("%d%d%d%d%d\n", dp[i][0], dp[i][1], dp[i][2], dp[i][3],dp[i][4]); // } printf("%I64d\n", (dp[l - 1][0] + dp[l - 1][1] + dp[l - 1][4]) % mod); } return 0;}// ?01???// ?// **12// 1// ************// 10101// 10000// 00100// 00001// 01011// 11112// 4// ************// 10101// 2// ************// 00001// 00001// 01000// 00000// 0// ************// 00100// 0
- cf404D Minesweeper 1D 状态转移dp
- D - Minesweeper 1D
- 404D Minesweeper 1D(记忆化搜索,dp)
- CF - 404 - D. Minesweeper 1D(dp)
- [计数连续dp] Codeforces D. Minesweeper 1D
- codeforce-404D---Minesweeper 1D(dp)
- CF237D Minesweeper 1D
- Minesweeper 1D
- Minesweeper 1D CodeForces
- CF D. Kefa and Dishes (状态转移dp)
- cf237,D.Minesweeper 1D (小范围后效性dp)
- Codefoeces 404D Minesweeper 1D "小范围后效性"dp
- cf404d
- CF 404D - Minesweeper 1D
- CodeForces 404D Minesweeper 1D
- Codeforces 404D Minesweeper 1D
- POJ3411 状态dp+松弛转移
- POJ 2686 (状态转移dp)
- POJ 3411
- flex十大未解之谜
- android进行网络连接时出现服务器拒绝访问的可能解决法
- unity3D中常用的几种系统自调用的重要方法
- Chromium开源项目的代码统计
- cf404D Minesweeper 1D 状态转移dp
- dex relate files
- 导出excel功能,较通用的一种实现
- 黑马程序员 Java基础之IO流<一>File类及递归
- 重温数据结构:哈希表,MyHashMap与MyHashSet的Java实现
- UI 血条批次优化
- session 与 cookie
- AAM与ASM的区别
- NGUI--怎么控制Input中的输入的字符长度和类型