HDU 5965 扫雷 模拟

版权声明:布呗之路的守望者 https://blog.csdn.net/hypHuangYanPing/article/details/82837417
/**
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5965
题意:如中文题面;
分析:可直接分析第一个状态的值 枚举几种状态,直接进行模拟即可;
判断好边界条件 边界存在状态并不是很多 仔细处理即可;
*/

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int mod=100000007;
const int maxn=1e5+7;
char str[maxn];
int len;

ll solve(int st,int now,int ans){
    int x,tmp;
    for(int i=1;i<len-1;i++){
        x=str[i]-'0';
        if(x<st+now||x>st+now+2) return 0;
        else if(x==st+now) st=now,now=0;
        else if(x==st+now+1) st=now,ans=2*ans%mod,now=1;
        else st=now,now=2;
    }
    x=str[len-1]-'0';
    return st+now==x?ans:0;
}

int main(){
    int t;scanf("%d",&t);
    while(t--){
        ll ans=0;
        scanf("%s",str);len=strlen(str);
        if(len==1){
            ll x=str[0]-'0';
            if(x==0) ans=1;
            else if(x==1) ans=2;
            else if(x==2) ans=1;
        }
        else if(str[0]=='0') ans=solve(0,0,1)%mod;
        else if(str[0]=='1') ans=(solve(1,0,2)+solve(0,1,2))%mod;
        else if(str[0]=='2') ans=(solve(1,1,4)+solve(2,0,1)+solve(0,2,1))%mod;
        else if(str[0]=='3') ans=(solve(1,2,2)+solve(2,1,2))%mod;
        else if(str[0]=='4') ans=solve(2,2,1);
        printf("%lld\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hypHuangYanPing/article/details/82837417