Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define LL long long int
- #define PB push_back
- #define PF push_front
- #define N 100005
- #define INF 1000000000
- using namespace std;
- int n,v[105];
- const int M=1e9+7;
- LL fact[200005],invfact[200005],dp[105];
- LL lgpow(LL a,LL p)
- {
- LL val=1,x=a%M;
- while(p>0)
- if(p%2==0)
- {
- x=x*x%M;
- p/=2;
- }
- else
- {
- val=val*x%M;
- p--;
- }
- return val;
- }
- int main()
- {
- cin>>n;
- for(int i=1;i<=n;++i)
- cin>>v[i];
- fact[0]=1;
- for(int i=1;i<=200000;++i)
- fact[i]=(1LL*fact[i-1]*i)%M,invfact[i]=lgpow(fact[i],M-2);
- invfact[0]=1;
- dp[0]=1;
- for(int i=1;i<=n;++i)
- {
- vector<LL> dp2(n+5,0),newdp(n+5,0);
- for(int j=1;j<=v[i];++j)
- {
- int p=(i*j)%n;
- LL jos=1LL*(invfact[j]*invfact[v[i]-j])%M;
- dp2[p]=(dp2[p]+(1LL*fact[v[i]]*jos)%M)%M;
- }
- for(int j=0;j<n;++j)
- {
- for(int d=0;d<n;++d)
- {
- int r=(j-d+n)%n;
- newdp[j]=(newdp[j]+(1LL*dp[d]*dp2[r])%M)%M;
- }
- }
- for(int j=0;j<n;++j)
- dp[j]=(dp[j]+newdp[j])%M;
- }
- cout<<dp[0];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement