当前位置:网站首页>【暑期每日一题】洛谷 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;
} 边栏推荐
猜你喜欢

Vscode连接远程服务器出现‘Acquiring lock on/home/~’问题

Clapper that can interact with the audience in real time

HCIP BGP Comprehensive Experiment Establishing peers, route reflectors, federation, route announcement and aggregation

武汉高性能计算大会2022举办,高性能计算生态发展再添新动力

8/1 思维+扩展欧几里得+树上dp

node安装及环境配置

Specified URL is not reachable,caused by :‘Read timed out

关于ue4.27像素流送打包后的本地服务器问题

View source and switch mirrors in two ways: npm and nrm

Pagoda+FastAdmin 404 Not Found
随机推荐
MySQL Advanced Statements (1)
打卡day05
Vscode连接远程服务器出现‘Acquiring lock on/home/~’问题
The installation of NPM, CNPM
Submit code process
Clapper that can interact with the audience in real time
关于ue4.27像素流送打包后的本地服务器问题
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
C# FileInfo类
MySQL - Multi-table query and case detailed explanation
rhce homework
love
Not annotated parameter overrides @NonNullApi parameter
MySQL Advanced SQL Statements (2)
Two good php debug tutorials
node安装及环境配置
mysql高阶语句(一)
宝塔+FastAdmin 404 Not Found
(部分不懂,笔记整理未完成)【图论】差分约束
Detailed explanation of 9 common reasons for MySQL index failure