惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
P
Palo Alto Networks Blog
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
aimingoo的专栏
aimingoo的专栏
腾讯CDC
T
Threatpost
D
DataBreaches.Net
Vercel News
Vercel News
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
Forbes - Security
Forbes - Security
U
Unit 42
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
O
OpenAI News
量子位
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
S
Security Affairs
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
I
Intezer
Know Your Adversary
Know Your Adversary
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
博客园_首页
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

Makerlife 的小站

2025-2026 赛季 游记 && 退役记 NOIP 2024 游记 集训记录 CSP2024 游记 板子库 动态规划 刷题记录 杂题乱记 数学期望 学习笔记 数论 学习笔记 CF1000F One Occurrence 题解 P6878 [JOI 2020 Final] JJOOII 2 题解 CSP2023 游寄 主定理 CF1695C Zero Path 题解 字符串算法全家桶 学习笔记 AT_ABC306D 题解 2023.06.03 模拟赛 Azure for Students 使用指北 AT_ABC286C 题解 洛谷 AT1898 题解 洛谷 CF1036A 题解 洛谷 CF1040A 题解 洛谷 SP3591 题解 洛谷 AT278 题解 洛谷 CF141B 题解 洛谷 AT2561 题解 洛谷 AT3525 题解 洛谷 CF899B 题解 洛谷 AT4810 题解 洛谷 SP5450 题解
洛谷 AT4787 题解
Makerlife · 2022-01-27 · via Makerlife 的小站

洛谷题目传送门 | AT原题传送门

思路

这其实是一道递推题。

打眼一看,这道题和P1255 数楼梯是差不多的,只不过是本题又新增了一个条件:有 mm 个楼梯是坏的。

如果没有这个条件,我们可以定义,第 ii 阶楼梯的总方案数为 fif_i,从题目中可以很容易得出:fi=fi−1+fi−2(i≥2)f_i=f_{i-1}+f_{i-2}(i \geq 2),因为只能从第 i−1i-1 和第 i−2i-2 阶楼梯上到第 ii 阶楼梯。

加上那个条件后,我们可以定义一个 bool\texttt{bool} 数组 vis\texttt{vis},如果第 ii 阶楼梯是坏的,那 visi=truevis_i=true,否则 visi=falsevis_i=false

有几点需要注意:

  1. 每次递推都需  mod 109+7\bmod 10^9+7
  2. 如果连续两阶楼梯都是坏的,也就是 visi=truevis_i=truevisi−1=truevis_{i-1}=true,直接输出 00 并退出程序(不判断也不会超时);
  3. 从第 00 阶台阶开始计算;
  4. f0f_0f1f_1 的初始值时要特判第 00 和第 11 阶楼梯是否损坏。

直接上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<cstdio>
#include<iostream>
using namespace std;
inline int read()//快读
{
int s=0,w=1;
char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0' && ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
const int mod=1e9+7;
int n,m,a,f[100010];
bool vis[100010]={0};
int main()
{
n=read();m=read();
for(int i=1;i<=m;i++)
{
a=read();
vis[a]=1;//标记该台阶已损坏
if(vis[a] && vis[a-1])//判断是否有连续两个台阶是坏的
{
cout<<0<<endl;
return 0;
}
}
if(!vis[0])//特判第0和第1阶楼梯是否损坏
{
f[0]=1;
}
if(!vis[1])
{
f[1]=1;
}
for(int i=2;i<=n;i++)
{
if(vis[i]) f[i]=0;//如果该楼梯损坏,则无法上到该楼梯
else
{
f[i]=(f[i-1]+f[i-2])%mod;//递推式(不要忘了取模)
}
}
cout<<f[n]<<endl;
return 0;
}

记得结尾要换行哦