P1192 Step problem (dp|recursion)

Insert picture description here
I never knew how to write this question before, but now I understand it;
in fact, it can be considered like this, for example: k=2 If I am on the i-th ladder, then my last ladder can only be i-1, i- 2 These two steps, so the total number of plans should be F[i]=F[i-1]+F[i-2]; F[i] here represents the total number of plans to reach the i step; so according to this idea, we just You can deduce this formula:
F[i]=F[i-1]+F[i-2]+F[i-3]+…+F[ik];
so the integration should be like this:
Insert picture description here
here I am i>=1, because F[0]=1, because standing in place is a kind of itself;
rather than saying that this question is dp, in fact, I feel that dp is to find the recursive formula, but complicated dp can be It's not that easy;
AC code:

#include<bits/stdc++.h>
using namespace std;
#define Mod 100003
int F[100050];
int main(){
    
    
	int n , k;
	scanf("%d %d",&n,&k);
	F[0]=1;
	for(int i=1;i<=n;i++){
    
    
		 for(int j=1;j<=min(i,k);j++){
    
    
		 	F[i]=(F[i]+F[i-j])%Mod;
		 }
	}
	printf("%d\n",F[n]%Mod);
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44555205/article/details/104199880