题目描述
有NN级的台阶,你一开始在底部,每次可以向上迈最多KK级台阶(最少11级),问到达第NN级台阶有多少种不同方式。
输入格式
两个正整数N,K。
输出格式
一个正整数,为不同方式数,由于答案可能很大,你需要输出ans mod 100003ansmod100003后的结果。
输入输出样例
输入 5 2
输出 8
说明/提示
对于20\%20%的数据,有N ≤ 10, K ≤ 3N≤10,K≤3;
对于40\%40%的数据,有N ≤ 1000N≤1000;
对于100\%100%的数据,有N ≤ 100000,K ≤ 100N≤100000,K≤100。
1 #include<bits/stdc++.h> 2 const int mod=100003; 3 const int N = 1e6+2; 4 int a[N],n,k; 5 using namespace std; 6 int main() 7 { 8 cin>>n>>k; 9 a[0]=a[1]=1; 10 for(int i = 2;i<=n;++i){ 11 if(i<=k)a[i]=a[i-1]*2%mod; 12 else a[i]=a[i-1]*2-a[i-k-1],a[i]%=mod; 13 } 14 cout<<(a[n]+mod)%mod<<endl; 15 return 0; 16 }
第一篇题解写的代码无敌简单orz,困得要死水了一题,但是公式好像一时半会还解释不清楚orz
后面几个方法复杂了一点点然后看到了用矩阵求斐波那契数列的博客,,我好菜啊一直在补早就该学会的东西