#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define MOD (ll) (1e9+7)
int compatible[21][21];
int dp[1<<21];
int main() {
ios_base::sync_with_stdio(false);
ll n; cin>>n;
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
cin>>compatible[i][j];
}
}
dp[0]=1;
for(int subset = 0; subset<(1<<n); subset++) {
int numberOfPairs = __builtin_popcount(subset); // number of women that are paired already
for(int woman=0; woman<n; woman++) {
if((subset&(1<<woman))) continue; // if this woman is already paired, continue
if(!compatible[numberOfPairs][woman]) continue; // if this woman is not compatible with the next man, continue
dp[subset | (1<<woman)] += dp[subset]; // add woman to subset and update dp value
dp[subset | (1<<woman)] %= MOD;
}
}
cout<<dp[(1<<n)-1]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |