题意: 求用K个不超过N的非负整数组成N的组合有多少种。
思路:瞎求。DP或者数论都行。本弱用了自顶向下的带备忘的DP,捡方便。设F(N,K)为答案,
那么F(N,K)=Sum(F(i,K-1),0<=i<=N)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#define DB puts("**de**")
#define WATCH(a) cout << a << endl
#define REP(i,n) for(int i=0;i<n;++i)
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define CL(a,b) memset(a,b,sizeof(a))
#define LL long long
#define FD(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define pr pair<int,int >
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
//const
const int MAXN=1e6+5;
const int INF=0x3f3f3f3f;
//struct
//global
//vector<int> edge[MAXN];
int ti1,ti2,ti3,n,m,t,k,ncase,fa[105][105];
double td1,td2,td3;
char tc1,tc2;
//func
LL f(int n,int k)
{
if(!k)
return 0;
if(fa[n][k])return fa[n][k];
if(k==1)
{
return 1;
}
if(k==2)
{
fa[n][k]=n+1;
return n+1;
}
LL tp=0;
for(int i=0;i<=n;i++)
{
tp+=f(n-i,k-1);
tp=tp%1000000;
}
fa[n][k]=tp%1000000;
return tp;
}
int main()
{
//freopen("C:\\Users\\inkysakura\\Desktop\\testdata.txt","r",stdin);
while(scanf("%d %d",&n,&k),n||k)
{
cout << f(n,k)%1000000<<endl;
}
return 0;
}