This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |