-
Notifications
You must be signed in to change notification settings - Fork 0
/
One_Unit_Machine.cpp
79 lines (77 loc) · 1.32 KB
/
One_Unit_Machine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Author : Syed Mujtaba
// Seek knowledge from the Cradle to the Grave !!
// https://www.linkedin.com/in/syed-mujtaba-064a5016a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007 // 1e9 + 7
int fact[1000007]={0};
int xyp(int x,int y)
{
int res=1;
while(y>0)
{
if(y%2==1)
res=(res*x)%mod;
x=(x*x)%mod;y/=2;
}
return res%mod;
}
void init()
{
fact[0]=1;
fact[1]=1;
for(int i=2;i<1000007;i++)
fact[i]=(fact[i-1]*i)%mod;
}
int ncr(int n,int r)
{
int res=1;
res=fact[n];
res=(res*(xyp(fact[r],mod-2)))%mod;
res=(res*(xyp(fact[n-r],mod-2)))%mod;
return res;
}
int add(int a, int b)
{
return (a%mod + b%mod)%mod;
}
int sub(int a, int b)
{
return (a%mod - b%mod + mod)%mod;
}
int mul(int a, int b)
{
return ((a%mod)*(b%mod))%mod;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
init();
int t;
cin >> t;
for(int q = 0; q < t; q++)
{
int n;
cin >> n;
vector < int > k(n);
for(auto &z : k)
cin >> z;
vector < int > ps(n + 1, 0);
ps[0] = 0;
for(int i = 1; i <= n; i++)
{
ps[i] = ps[i - 1] + k[i - 1];
}
int ans = 1;
for(int i = 1; i < n; i++)
{
int ss = ps[i];
int el = k[i];
ans = mul(ans, sub(ncr(ss + el, el), ncr(ss + el - 1, el)));
}
cout << "Case " << q+1 << ": " << ans << endl;
}
}