【codeforces 404D】Minesweeper 1D
【题目链接】:http://codeforces.com/problemset/problem/404/D
【题意】
让你玩一个1维的扫雷游戏;
游戏的描述由数字0..2以及符号*表示;
分别表示这个格子的相邻的两个格子里面有几个炸弹;以及炸弹;
然后挖一些空;
问你有多少种填满的方案;
【题解】
dp[i][1] 表示前i个位置,第i个位置放0的方案数
dp[i][2] 表示钱i个位置,第i个位置放1,前一位没炸弹的方案数
dp[i][3] …..放1,前一位有炸弹…..
dp[i][4] …..放2….
dp[i][5] ….放炸弹….
根据每一位是什么进行转移就可以了;
转移也很容易想的;
然后初值根据s[1]的值来置;
【Number Of WA】
3
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("D:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6+100;
const int MOD = 1e9+7;
char s[N];
int dp[N][6],ans,n;
inline void add(int &a,int &b){
a+=b;
if (a>=MOD) a-=MOD;
}
int main(){
//Open();
scanf("%s",s+1);
if (s[1]=='0'){
dp[1][1] = 1;
}else if (s[1]=='1'){
dp[1][2] = 1;
}else if (s[1]=='2'){
//dp[1][4] = 1;
}else if (s[1]=='*'){
dp[1][5] = 1;
}else{
dp[1][1] = dp[1][2] = dp[1][5] = 1;
}
n = (int) strlen(s+1);
//dp[i][1] 放0
//dp[i][2] 放1,前一位没炸弹
//dp[i][3] 放1,前一位有炸弹
//dp[i][4] 放2
//dp[i][5] 放炸弹
rep1(i,2,n){
if (s[i]=='0'){
add(dp[i][1],dp[i-1][1]);
add(dp[i][1],dp[i-1][3]);
}else if (s[i]=='1'){
add(dp[i][2],dp[i-1][1]);
add(dp[i][2],dp[i-1][3]);
add(dp[i][3],dp[i-1][5]);
}else if (s[i]=='2'){
add(dp[i][4],dp[i-1][5]);
}else if (s[i]=='*'){
add(dp[i][5],dp[i-1][2]);
add(dp[i][5],dp[i-1][4]);
add(dp[i][5],dp[i-1][5]);
}else if (s[i]=='?'){
add(dp[i][1],dp[i-1][1]);
add(dp[i][1],dp[i-1][3]);
add(dp[i][2],dp[i-1][1]);
add(dp[i][2],dp[i-1][3]);
add(dp[i][3],dp[i-1][5]);
add(dp[i][4],dp[i-1][5]);
add(dp[i][5],dp[i-1][2]);
add(dp[i][5],dp[i-1][4]);
add(dp[i][5],dp[i-1][5]);
}
}
add(ans,dp[n][1]),add(ans,dp[n][3]),add(ans,dp[n][5]);
cout << ans << endl;
return 0;
}
【codeforces 404D】Minesweeper 1D的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 255D】Mr. Bender and Square
[题目链接]:http://codeforces.com/problemset/problem/255/D [题意] 给你一个n*n的方框; 给你一个方块;(以下说的方块都是单位方块) 每一秒钟,可以 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
随机推荐
- async、await 优缺点
async.await 优缺点 async 和 await 相比直接使用 Promise 来说,优势在于处理 then 的调用链,能够更清晰准确的写出代码.缺点在于滥用 await 可能会导致性能问题 ...
- 使用 Xshell 连接 linux 系统
一.下载 Xshell 链接:https://pan.baidu.com/s/1htwqpzm 密码:zau7 二.安装 Xshell 无脑下一步就可以了 三.连接 linux 四.安装 Xftp h ...
- AIX查看某个端口被哪个进程占用
AIX查看某个端口被哪个进程占用 学习了:https://zhidao.baidu.com/question/1928716757722021467.html 1. netstat -Aan|grep ...
- 从头认识java-16.4 nio的读与写(ByteBuffer的使用)
这一章节我们来讨论一下nio的读与写. 1.nio的读 package com.ray.ch16; import java.io.IOException; import java.io.RandomA ...
- scikit-learn:3.5. Validation curves: plotting scores to evaluate models
參考:http://scikit-learn.org/stable/modules/learning_curve.html estimator's generalization error can b ...
- 杭电3501Calculation 2 欧拉函数
Calculation 2 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- TS 函数解析
------------------------------------------------------------------------------------ 函数传参: //let myA ...
- CoreData 从入门到精通(六)模型版本和数据迁移
前面几篇文章中讲的所有内容,都是在同一个模型版本上进行操作的.但在真实开发中,基本上不会一直停留在一个版本上,因为需求是不断变化的,说不定什么时候就需要往模型里添加新的字段,添加新的模型,甚至是大规模 ...
- zzulioj--1708--01串也疯狂之光棍也有伴(dp)
1708: 01串也疯狂之光棍也有伴 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 199 Solved: 50 SubmitStatusWeb B ...
- JAXB xml与javaBean的转换
转自:https://blog.csdn.net/lydong_/article/details/79812626 `1. 1.不认识到犯错,然后得到永久的教训. 也不是所谓的教训吧,真正的教训来自于 ...