sgu239:Minesweeper(暴力)

题目大意:
       给出长度为 n 的两列,其中一列有0...3的数,按照扫雷的规则求出另一列有多少种方案。

分析:
       稍微脑补一下我们可以发现只要确定了第一个那么整列都确定了。 so 我们枚举第一个再判断就行了。

AC code:

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#define ONLINE_JUDGE
typedef long long LL;
typedef double DB;
typedef long double LD;
using namespace std;

const int MAXN = 1009;

int n;
int s[MAXN];
int f[MAXN];

bool check(int x)
{
    memset(f, 0, sizeof(f));
    f[1] = x;
    for(int i = 1; i <= n; ++i)
    {
        f[i+1] = s[i]-f[i]-f[i-1];
        if(f[i+1] < 0 || f[i+1] > 1) return false;
    }
    return f[n+1] == 0;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("sgu239.in", "r", stdin);
    freopen("sgu239.out", "w", stdout);
    #endif

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", s+i);
    printf("%d\n", check(0)+check(1));

    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值