20分求调,k不等于2答案就错误
查看原帖
20分求调,k不等于2答案就错误
1532447
que_de_yu_fu楼主2024/11/24 14:48
#include<bits/stdc++.h>
using namespace std;
int n,k,c,f[100005]={1,2};
int main(){
	cin>>n>>k;
	if(n==0){
		cout<<"0";
	}
	else if(k==1){
		cout<<"1";
	}
	else{
		for(int i=2;i<=n;i++){
			for(int j=1;j<=k;j++){
				c=i-j;
				if(c>=0){
				
					f[i]+=f[i-j];
				}
				else{
					f[i]+=1;
				}
				
			}
		}	
		cout<<f[n-1];
	}
	return 0;
}

求调,k=2的时候一切正常,不等于2就全是错误,加了很多特判,只有20分

2024/11/24 14:48
加载中...