设函数 f(k)(n);
则:
f(1)(n)=1;
f(2)(n)=f(1)(0)+f(1)(1)+f(1)(2)+...+f(1)(n);
f(3)(n)=f(2)(0)+f(2)(1)+f(2)(2)+...+f(2)(n);
.
.
.
f(k)(n)=f(k-1)(0)+f(k-1)(1)+...+f(k-1)(n);
可预处理。
附代码:
#include <iostream>
#include <cstring>
using namespace std; int main (){
int n,k;
int f[][];
memset (f,,sizeof f);
for (int i=;i<=;i++)
f[][i]=;
for (int i=;i<=;i++){
for (int j=;j<=;j++){
for (int o=;o<=j;o++)
f[i][j]=(f[i][j]+f[i-][o])%;
}
}
while (cin>>n>>k&&(n+k)){
cout<<f[k][n]<<endl;
}
return ;
}