BZOJ1088 扫雷Mine [递推]

本文介绍了一种使用C++编程语言解决特定递归数列问题的方法。通过模板化的输入读取函数加速了数据处理,并利用动态规划的思想来枚举所有可能的数列起始值,进而判断该数列是否符合预设条件。最终输出符合条件的起始值数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
template<class T>inline void read(T &res){
    static char ch;T flag=1;
    while((ch=getchar())<'0'||ch>'9')if(ch=='-')flag=-1;res=ch-48;
    while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;res*=flag;
}
const int N = 100005,INF = 0x3f3f3f3f;
long long a[N],b[N],n,dp[N],ans;
bool judge(){
    for(register int i=3;i<=n+1;i++)
        a[i]=b[i-1]-a[i-1]-a[i-2];
    if(!a[n+1])return 1;
    else return 0;
}
int main(){
    read(n);
    for(register int i=1;i<=n;i++)read(b[i]);
    for(register int i=0;i<=b[1];++i){
        memset(a,0,sizeof(a));
        a[1]=i,a[2]=b[1]-i;
        if(judge())ans++;
    }
    cout<<ans<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值