HDU 5965 扫雷 模拟

/**
链接: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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值