This problem can be simplified to the number of the N ball in the K box, because each box can be empty, so we might as well add a K ball, so that we can at least ensure that a box has a ball, and then use the partition method to divide n + K ball, that is, n + K-1 to choose K-1 position C (n + K-1,K-1)
The solution method can be recursive.
Other than that:
number of permutations and combinations of C (m,n) =a (m,n)/n!
C (m,0) = 1;
0! = 1;
Code:
#include <cstdio> #include <cmath>using namespace std;typedef long long ll;const int MAXN = 222;const int Mod
= 1000000; LL c[maxn][maxn];void init () { c[1][0] = 1; C[1][1] = 1; for (int i = 2; I <=, i++) {for (int j = 0; J <= I; j + +) { if (j) c[i][j] = c[i-1][j-1] + c[i-1][j ]; else c[i][j] = 1; C[I][J]%= mod;}}} void Debug () {}int main () { init (); int n,m; while (scanf ("%d%d", &n,&m)! = EOF) { if (!n &&!m) break; LL ans = c[n + m-1][m-1]; printf ("%lld\n", ans); } return 0;}
10943-how Do you add? (Partition method)