Advertisement
a53

Bal

a53
Jun 11th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. cout.tie(0);
  8. const int MOD=1000000007;
  9. int n,r;
  10. char p;
  11. cin>>n;
  12. int upbound=(1<<n);
  13. vector<int> g(n),dp(upbound);
  14. for(int i=0;i<n;++i)
  15. for(int j=0;j<n;++j)
  16. {
  17. cin>>p;
  18. if(p=='1')
  19. g[i]|=(1<<j);
  20. }
  21. dp[0]=1;
  22. for(int x=1;x<upbound;++x)
  23. {
  24. p=__builtin_popcount(x),r=0;
  25. for(int y=x&g[p-1];y;y&=y-1)
  26. {
  27. r+=dp[x&~(y&-y)];
  28. if(r>=MOD)
  29. r-=MOD;
  30. }
  31. dp[x]=r;
  32. }
  33. cout<<dp[upbound-1];
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement