https://vjudge.net/problem/UVA-10943
题意:
把K个不超过N的非负整数加起来,使得它们的和为N,有多少种方法?
思路:
d[i][j]表示用i个数加起来为j的方法数。
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 7 const int maxn=100+5; 8 const int mod=1e6; 9 10 int n,k; 11 int d[maxn][maxn]; 12 13 int main() 14 { 15 while(cin>>n>>k && n && k) 16 { 17 memset(d,0,sizeof(d)); 18 d[0][0]=1; 19 for(int i=1;i<=k;i++) 20 for(int j=0;j<=n;j++) 21 for(int t=0;t<=j;t++) 22 { 23 d[i][j]+=d[i-1][t]; 24 d[i][j]%=mod; 25 } 26 cout<<d[k][n]<<endl; 27 } 28 return 0; 29 }