forked from Sahaj-Bamba/HacktoberTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnicarray.cpp
More file actions
73 lines (70 loc) · 1.05 KB
/
nicarray.cpp
File metadata and controls
73 lines (70 loc) · 1.05 KB
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
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define MOD 1000000007
using namespace std;
ll func(ll,ll,ll,ll);
ll GCD(ll,ll);
ll inv[55],fact[55],n,r; //n total no. of '-1', r remaining sum to be full filled
int main()
{
fact[0]=1;
rep(i,1,52)
{
fact[i]=(i*fact[i-1])%MOD;
inv[i]=i;
}
ll t;
cin>>t;
while(t--)
{
ll s,sum=0,t,ar[55];
n=0;
cin>>t>>s;
rep(i,0,t)
{
cin>>ar[i];
if(ar[i]==-1)
n++;
else
sum+=ar[i];
}
s-=sum;
ll ans=1;
rep(i,0,s-n+1)
{
ans+=func(1,i,1,r-i);
}
cout<<ans<<"\n";
}
}
/*ll inverse_(ll n)
{
}*/
ll GCD(ll a,ll b)
{
if(b==0)
return a;
else
return GCD(b,a%b);
}
ll func(ll idx,ll prev,ll cnt,ll r)
{
if(r<0)
return 0;
if(idx==n)
{
cout<<"\n";
return inv[cnt];
}
ll ans=0,mul;
if(r-prev<=r-(n-idx)+1)
ans+=func(idx+1,prev,cnt+1,r-prev);
rep(i,prev+1,r-(n-idx)+2)
{
mul=cnt;
ans+=(func(idx+1,i,0,r-i)*inv[cnt])%MOD;
}
return ans;
}