Advertisement
a53

Subset Fight

a53
Dec 11th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define LL long long int
  3. #define PB push_back
  4. #define PF push_front
  5. #define N 100005
  6. #define INF 1000000000
  7. using namespace std;
  8. int n,v[105];
  9. const int M=1e9+7;
  10. LL fact[200005],invfact[200005],dp[105];
  11.  
  12. LL lgpow(LL a,LL p)
  13. {
  14. LL val=1,x=a%M;
  15. while(p>0)
  16. if(p%2==0)
  17. {
  18. x=x*x%M;
  19. p/=2;
  20. }
  21. else
  22. {
  23. val=val*x%M;
  24. p--;
  25. }
  26. return val;
  27. }
  28.  
  29. int main()
  30. {
  31. cin>>n;
  32. for(int i=1;i<=n;++i)
  33. cin>>v[i];
  34. fact[0]=1;
  35. for(int i=1;i<=200000;++i)
  36. fact[i]=(1LL*fact[i-1]*i)%M,invfact[i]=lgpow(fact[i],M-2);
  37. invfact[0]=1;
  38. dp[0]=1;
  39. for(int i=1;i<=n;++i)
  40. {
  41. vector<LL> dp2(n+5,0),newdp(n+5,0);
  42. for(int j=1;j<=v[i];++j)
  43. {
  44. int p=(i*j)%n;
  45. LL jos=1LL*(invfact[j]*invfact[v[i]-j])%M;
  46. dp2[p]=(dp2[p]+(1LL*fact[v[i]]*jos)%M)%M;
  47. }
  48. for(int j=0;j<n;++j)
  49. {
  50. for(int d=0;d<n;++d)
  51. {
  52. int r=(j-d+n)%n;
  53. newdp[j]=(newdp[j]+(1LL*dp[d]*dp2[r])%M)%M;
  54. }
  55. }
  56. for(int j=0;j<n;++j)
  57. dp[j]=(dp[j]+newdp[j])%M;
  58. }
  59. cout<<dp[0];
  60. return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement