SPOJ
来源:互联网 发布:java http请求框架 编辑:程序博客网 时间:2024/06/16 20:15
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 149000
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;}
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- Linux-鸟菜-4-关机的正确姿势
- Java学习笔记33--ajax提交表单
- Eclipse将引用了第三方jar包的Java项目打包成jar文件的两种方法
- 关于进程
- Result Maps collection already contains value for Mapper.BaseResultMap错误原因
- SPOJ
- 图书管理系统2
- 2017第八届浪潮杯山东省赛 A.Return of the Nim 博弈
- HPU2016级暑期集训选拔赛 【题解】
- 从零开始学_JavaScript_系列(38)——对象的扩展(1)属性的简洁写法
- php设计模式之策略模式
- Kotlin 官方学习教程之可见性修饰符
- 抽象类和接口的区别
- 指针常量和常量指针