当前位置:网站首页>【暑期每日一题】洛谷 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;
}
边栏推荐
猜你喜欢
HCIP 第一天
Nodejs installation and global configuration (super detailed)
CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
Clapper that can interact with the audience in real time
mysql高阶语句(一)
ASP.NET Core Web API 幂等性
Node installation and environment configuration
CAT1 4G+以太网开发板腾讯云手机微信小程序显示温度和下发控制
MySQL - Multi-table query and case detailed explanation
Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
随机推荐
mysql索引失效的常见9种原因详解
typescript 'props' is declared but its value is never read solution
MySQL经典50道练习题及全网最详细解析
Nacos installation detailed process
MySQL高阶---存储引擎、索引、锁
HCIP 第二天
MySQL - Multi-table query and case detailed explanation
MySql - there is no insert, there is update or ignored
MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
July 18-July 31, 2022 (Ue4 video tutorials and documentation, 20 hours. Total 1412 hours, 8588 hours left)
MySQL高级-MVCC(超详细整理)
A detailed introduction to the deployment and usage of the Nacos registry
postgres 多个变量填充字符串,字串格式化
Pagoda+FastAdmin 404 Not Found
Go inside the basic knowledge
How does abaqus quickly import the assembly of other cae files?
(部分不懂,笔记整理未完成)【图论】差分约束
HCIP day one
MySQL高级SQL语句
DNS resolution process