Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- using namespace std;
- int n;
- int mat[30][30];
- int dp[2500000];
- int const mod=1e9 +7;
- int f(int k)
- {
- int pos = __builtin_popcount(k);
- if(pos==n)
- {
- if(k==(1<<n)-1)
- {
- return 1;
- }
- return 0;
- }
- if(dp[k]!=-1)
- {
- return dp[k];
- }
- int rez=0;
- for(int j=0;j<n;j++)
- {
- if(k&(1<<j))
- {
- }
- else
- {
- if(mat[pos][j]==1)
- {
- int kn=k;
- kn|=(1<<j);
- rez+=f( kn);
- rez%=mod;
- }
- }
- }
- return dp[k]=rez%mod;
- }
- int main()
- {
- memset(dp,-1,sizeof dp);
- cin>>n;
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<n;j++)
- {
- cin>>mat[i][j];
- }
- }
- cout<<f(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement