#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6+18;
const int mod = 1e9+7;
const double eps = 1e-10;
#define bug(x) cout<<#x<<"=="<<x<<endl;
typedef pair<int,int> pp;
int sta[maxn] = { 0 };
int c[maxn] = { 0 };
ll dp[3] = { 1,1,0};
///当前点无炸弹,下一个点也无炸弹
///当前点无炸弹,下一个点有炸弹
///当前点有炸弹,下一个点...未知
int main()
{
string a;
cin>>a;
for(int i=0;i<a.length();i++)
{
ll now[3] = { 0 };
if(a[i]=='0'||a[i]=='?')
{
now[0] += dp[0];
now[0]%=mod;
///后面和下一个位置没有炸弹
}
if(a[i]=='1'||a[i]=='?')///当前位置两边有一个炸弹
{
now[0] +=dp[2];///当前位置下一个位置无炸弹,上一个位置有炸弹
now[1] += dp[0];///当前位置的上一个位置无炸弹,下一个位置有炸弹
now[0]%=mod;
now[1]%=mod;
}
if(a[i]=='2'||a[i]=='?')
{
now[1] += dp[2];///上一个位置有炸弹,下一个位置也有
now[1]%=mod;
}
if(a[i]=='*'||a[i]=='?')
{
now[2] += (dp[2]+dp[1]);///表示i位置有炸弹,而且只有上一个位置是炸弹或者是1才可能合法
now[2] %= mod;
}
for(int j=0;j<=2;j++)
{
now[j]%=mod;
dp[j] = now[j];
}
}
printf("%lld\n",(dp[0]+dp[2])%mod);
///因为最后一个位置的下一个位置肯定是无炸弹的,所以是dp[0],dp[2];
}
上一篇
cf 189 A
2021-09-10
下一篇
CF5C Longest Regular Bracket Sequence
2021-09-08