Light OJ 1102

Source: Internet
Author: User
Tags mul

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.