当前位置:网站首页>【暑期每日一题】洛谷 P1192 台阶问题
【暑期每日一题】洛谷 P1192 台阶问题
2022-08-02 06:07:00 【AC_Dragon】
题目链接:P1192 台阶问题 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目描述
有 N 级的台阶,你一开始在底部,每次可以向上迈最多 K 级台阶(最少 1 级),问到达第 N 级台阶有多少种不同方式。
输入格式
两个正整数N,K。
输出格式
一个正整数,为不同方式数,由于答案可能很大,你需要输出 ans mod 100003 后的结果。
样例 #1
样例输入 #1
5 2样例输出 #1
8提示
对于 20% 的数据,有 N ≤ 10, K ≤ 3;
对于 40% 的数据,有 N ≤ 1000;
对于 100% 的数据,有 N ≤ 100000,K ≤ 100。
AC code:
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
ll f[N]; // f[n]表示从第1阶台阶到第n阶的走法数
int main()
{
int n,k;
cin>>n>>k;
f[1]=1;
for(int i=2;i<=100000;i++)
{
for(int j=0;j<k;j++)
{
if(1<=i-k+j && i-k+j<i) // if(1<=i-k+j)
f[i]=(f[i]+f[i-k+j])%100003;
}
if(i<=k)
f[i]++;
}
cout<<f[n];
return 0;
} 边栏推荐
猜你喜欢
随机推荐
npm does not recognize the "npm" item as the name of a cmdlet, function, script file, or runnable program.Please check the spelling of the name, and if the path is included, make sure the path is corr
暑期总结(三)
数据库概论之MySQL表的增删改查1
Toolbox App 1.25 New Features at a Glance | Version Update
abaqus如何快速导入其他cae文件的assembly?
In-depth analysis of the initialization of member variables and local variables
MySQL high-level --- storage engine, index, lock
MySQL union query (multi-table query)
optional
关于ue4.27像素流送打包后的本地服务器问题
PMP新考纲通关秘籍,告别抓瞎
Connection reset by peer 问题解析
Nacos installation detailed process
Revitalize rural circular economy and digital chain to link agricultural "ecological chain"
MySQL高级语句(一)
Toolbox App 1.25 新功能一览 | 版本更新
MySQL驱动jar包的下载--保姆教程
npm ---- install yarn
typescript ‘props‘ is declared but its value is never read 解决办法
HCIP day one


![[数据集][VOC]眼睛佩戴数据集VOC格式6000张](/img/66/37f76d9ce5d5f68d6ea0e18710fa04.png)






