Test instructions: Give you a number N, to divide the number of K (can be 0) of the species;
Idea: Similar in the K drawer put N apples, not for 0, is in n-1 a gap choose m-1;
is 0, you can first in the K drawer an apple, and then similar;
So the answer is C (n+k-1, K-1);
Large data, also control memory ... Bitwise multiplication + Inverse element
#include <bits/stdc++.h>using namespace std;typedef int ll;const int MAXN = 2000000 + 131;const LL MOD = 1000000007;l L Mul (ll A, ll B, ll m) {a = (a% m + m)% m; b = (b% m + m)% m; LL ret = 0; while (b) {if (b & 1) ret = (ret + a)% m; b >>= 1; a <<= 1; A%= m; } return ret;} ll Pow_mod (ll A, ll N, ll m) {ll ret = 1; while (n) {if (N & 1) ret = Mul (ret, A, m); n >>= 1; A = Mul (A, A, m); } return ret;} LL NUM[MAXN], inv[maxn];void Init () {num[0] = 1; for (LL i = 1; i < MAXN; ++i) Num[i] = Mul (num[i-1], I, MOD); Inv[maxn-1] = Pow_mod (num[maxn-1], MOD-2, Mod); for (LL i = maxn-2; I >= 0; i.) inv[i] = Mul (inv[i+1], (i+1), MOD);} ll C (ll M, ll N, ll MoD) {if (n = = 0 | | n = = m) return 1; LL ret = 1; LL s = m-n; ret = Mul (Num[m], inv[s], MoD); ret = Mul (ret, inv[n], MoD); return ret;} int main () {Init (); int t; LL N, K; scanf ("%d", &amP;T); for (int kase = 1; kase <= T; ++kase) {scanf ("%d%d", &n, &k); printf ("Case%d:%d\n", Kase, C (n+k-1, K-1, MOD)); }}
Light OJ 1102