554C - Kyoya and Colored Balls - CodeForces Solution


combinatorics dp math *1500

Please click on ads to support us..

C++ Code:

// Nishant's Code
#include <bits/stdc++.h>
using namespace std;
#define T                   \
    ll no_of_testcases;     \
    cin >> no_of_testcases; \
    f(curr_testcase, 1, no_of_testcases + 1)

#define ll long long
#define ld long double
const ll M = 1e9 + 7;
const ll M1 = 998244353;
const ll inf = 1e18 + 10;
const ll inf_ = -1e18 - 10;
ll max(ll x, ll y) { return x > y ? x : y; }
ll min(ll x, ll y) { return x < y ? x : y; }
ll gcd(ll x, ll y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
#define bp __builtin_popcountll
#define bclz __builtin_clzll
#define bctz __builtin_ctzll

#define f(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define f_(i, n, m) for (ll i = (ll)n; i >= (ll)m; i--)
#define fa(i, x) for (auto i : x)
#define vll vector<ll>
#define vvll vector<vll>
#define vb vector<bool>
#define vvb vector<vb>
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define ff first
#define ss second
#define vpll vector<pll>
#define v(x) vector<x>
#define p(x, y) pair<x, y>
#define all(x) x.begin(), x.end()

#define um unordered_map
#define us unordered_set
#define ms multiset
#define pqllMaxHeap priority_queue<ll>
#define pqllMinHeap priority_queue<ll, vector<ll>, greater<ll>>
#define pqpll priority_queue<ppll, vector<ppll>, greater<ppll>>
#define pq(x) priority_queue<x, vector<x>, greater<x>>
#define ub upper_bound
#define lb lower_bound

#define pb push_back
#define mp make_pair
#define acc accumulate
#define in insert
#define clr clear
#define nl cout << "\n";

void solve()
{
    //CODE HERE
    ll k;
    cin >> k;
    vll c(k);
    f(i, 0, k)
    {
        cin >> c[i];
    }
    // As nCr= n-1Cr + n-1Cr-1
    vvll nCr(1005, vll(1005, 0));
    nCr[0][0] = 1;
    f(i, 1, 1005)
    {
        nCr[i][0] = 1;
        f(j, 1, i + 1)
        {
            nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % M;
        }
    }
    ll tot = 0;
    ll ans = 1;
    f(i, 0, k)
    {
        tot += c[i];
        ans = (ans * nCr[tot - 1][c[i] - 1]) % M;
    }
    cout << ans;
    nl
}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    solve();
}


Comments

Submit
0 Comments
More Questions

1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training
1646C - Factorials and Powers of Two
596A - Wilbur and Swimming Pool
1462B - Last Year's Substring
1608B - Build the Permutation
1505A - Is it rated - 2
169A - Chores
765A - Neverending competitions
1303A - Erasing Zeroes
1005B - Delete from the Left
94A - Restoring Password
1529B - Sifid and Strange Subsequences
1455C - Ping-pong
1644C - Increase Subarray Sums
1433A - Boring Apartments
1428B - Belted Rooms
519B - A and B and Compilation Errors
1152B - Neko Performs Cat Furrier Transform
1411A - In-game Chat
119A - Epic Game
703A - Mishka and Game
1504C - Balance the Bits
988A - Diverse Team
1312B - Bogosort
1616B - Mirror in the String
1660C - Get an Even String
489B - BerSU Ball
977C - Less or Equal