HDU - 5965 -- 扫雷

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=5965

中文题面= =。

我们考虑每一列,只可能安放0,1,2个雷。对于每一种情况,假如第一列的雷数确定了,那么后面的每一列都确定了,每一列的安放数量为num[i]=a[i-1]-num[i-1]+num[i-2]。但可能会出现不合题意的情况,因而需要检验a[n]是否满足题意。

代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define ll long long
#define ull unsigned long long
#define BUG printf("************\n")
using namespace std;
ll gcd(ll a,ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a,ll b) {
    return a / gcd(a, b) * b;
}
ll pow_mod(ll a, ll b, ll mod) {
    ll ans = 1;
    while (b) {
        if (b & 1)ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans % mod;
}
bool is_prime(ll n) {
    if (n == 1 || n == 2)return 1;
    for (int i = 2; i <= sqrt(n); ++i)
        if (n % i == 0)return 0;
    return 1;
}
const ull mod = 1e8 + 7;
const int maxn = 4e5 + 10;
const int maxm = 1e6 + 10;
const double eps = 1e-8;

int n,num[maxn],a[maxn];
char c[maxn];
ull dp(int x) {
    num[1] = x;
    if (num[1] > a[1])return 0ull;
    if (n == 1 && num[1] != a[1])return 0ull;
    for (int i = 2; i <= n; ++i) {
        num[i] = a[i - 1] - num[i - 1] - num[i - 2];
        if (num[i] > 2 || num[i] < 0)return 0ull;
    }
    if (a[n] != num[n] + num[n - 1])return 0ull;
    ull ans = 1;
    for (int i = 1; i <= n; ++i) {
        if (num[i] == 1)ans = ans * 2;
        if (ans > 1e17)ans %= mod;
    }
    return ans % mod;
}
int main() {
    /*ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/
    int _;
    scanf("%d", &_);
    while (_--) {
        scanf("%s", c + 1);
        n = strlen(c + 1);
        for (int i = 1; i <= n; ++i)
            a[i] = c[i] - '0';
        printf("%lld\n", dp(0) + dp(1) + dp(2));
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值