이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |