题意:给你N个数,问有多少种方法使得用K个数的和为N,且这K个数都不大于N,跟之前的一题的隔板法是一样的,将N个数分成K个部分,允许空,所以答案就是在N+K-1个数中选K-1个数,因为想着递推查了一下公式:c(n,m)=c(n-1,m-1)+c(n-1,m)
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 200;
int f[MAXN][MAXN];
int main(){
memset(f,0,sizeof(f));
for (int i = 0; i < MAXN; i++)
f[i][0] = 1;
for (int i = 1; i < MAXN; i++)
for (int j = 1; j <= i; j++)
f[i][j] = (f[i-1][j]+f[i-1][j-1]) % 1000000;
int n,k;
while (scanf("%d%d",&n,&k) != EOF && n+k){
printf("%d\n",f[n+k-1][k-1]);
}
return 0;
}