SPOJ - VSTEPS Steps ( 递推

在电脑游戏“LuckyLuke”中,Lucky需要爬上一个由n个台阶组成的楼梯,某些台阶已损坏无法使用。本篇博客探讨了如何计算Lucky能够成功到达顶部的不同路径数量,并提供了一段AC代码实现。

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

Steps

Description

While playing the computer game “Lucky Luke”, Bom arrived at a scenario in which Lucky has to climb a staircase consisting of n steps.

The steps are numbered as 1 to n from bottom to top. Lucky may go up one step, or may jump two steps at once. However, some steps are broken and Lucky cannot stand on them. In the beginning, Lucky stands on the first step (the first step is never broken).

Suddenly, Bom arrived at a question: how many ways for Lucky to climb the staircase? (i.e. to stand on the nth step). Bom needs your help to answer this question.

Input

The first line consisting of two integers n and k; n is the number of steps in the staircase and k is the number of broken steps (0 ≤ k < n ≤ 100000).
The second line consisting of k integers which are the indexes of the broken steps in ascending order.

Output

Print out the remainder of the number of ways for Lucky to climb the staircase when divided to 14062008.

Sample Input

90000 1
49000

Sample Output

4108266Steps

Hint

题意

在玩电脑游戏“Lucky Luke”时,Bom到达了一个场景,Lucky必须爬上一个由n个台阶组成的楼梯。

楼梯从下到上编号为1到n。 Lucky可能会往上爬一步,或者可能一次跳两步。 然而,一些台阶被打破了,Lucky不能站在上面。 一开始,Lucky站在第一阶(第一阶永远不会破)。

突然,Bom想到了一个问题:Lucky爬楼梯到第n阶楼梯有多少种方法?
Bom需要你的帮助来回答这个问题。

题解:

大水题一枚 稍微推一下就知道是个斐波那契

AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+5;
const int mod = 14062008;
bool vis[N];
LL f[N];
int main()
{
    memset(vis,true,sizeof(vis));
    int n, k;
    int x;
    scanf("%d%d",&n,&k);
    for(int i = 0;i < k; i++) {
        scanf("%d",&x);
        vis[x] = false;
    }
    for(int i = 1;i <= n-1; i++) {
        if(!vis[i]&&!vis[i+1]) {
            printf("0");
            return 0;
        }
    }
    if(!vis[n]) {
        printf("0"); return 0;
    }
    f[1] = 1;
    for(int i = 2;i <= n; i++ ) {
        if(vis[i]) f[i] = (f[i-1]%mod+f[i-2]%mod)%mod;
        else f[i] = 0; 
    }
    printf("%lld\n",f[n]);
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值