10.3
mine
思路:
简单dp
#include <cstdio>
#include <cstring>
#define LL long long
#define N 5000010
const LL mod = 1e9 + 7;
int len;
char s[N];
LL f[N][5], ans = 0;
//5种状态 0:以0结尾 1:以*1结尾 2:以1结尾(1前无*) 3:以2结尾 4:以*结尾
int main(){
freopen("mine.in","r",stdin);
freopen("mine.out","w",stdout);
scanf("%s", s+1);
len = strlen(s + 1);
f[0][0] = 1;
for(int i=1; i<=len; i++){
if(s[i]=='?' || s[i]=='0') f[i][0] = (f[i-1][0] + f[i-1][1]) % mod;
if(s[i]=='?' || s[i]=='1') f[i][1] = f[i-1][4], f[i][2] = (f[i-1][0] + f[i-1][1]) % mod;
if(s[i]=='?' || s[i]=='2') f[i][3] = f[i-1][4];
if(s[i]=='?' || s[i]=='*') f[i][4] = (f[i-1][4] + f[i-1][2] + f[i-1][3]) % mod;
if((s[i]=='?' || s[i]=='*') && i == 1) f[i][4] = 1;
}
ans = (f[len][0] + f[len][1] + f[len][4]) % mod;
printf("%I64d\n", ans);
return 0;
}