#include "bits/stdc++.h"
#define ll long long
#define int ll
using namespace std;
const int sz = 25;
int vi[1ll << sz][sz];
ll dp[1ll << sz][sz];
int tw[sz], tr[sz];
int a[sz], n;
bool matc(int i, int j) {
if (tw[i] == tw[j] || tr[i] == tr[j])
return true;
return false;
}
ll go(int i, int bt) {
if (bt == (1ll << n) - 1) return 1ll;
int& v = vi[bt][i];
ll& r = dp[bt][i];
if (v) return r;
v = 1;
for (int j = 0; j < n; j ++) {
int f = bt & (1ll << j);
if (!f && matc(i, j))
r += go(j, bt | (1 << j));
}
return r;
}
void zero() {
for (int i = 0; i < (1ll << n); i ++)
for (int j = 0; j < n; j ++)
dp[i][j] = vi[i][j] = 0;
}
signed main() {
cin >> n;
for (int i = 0; i < n; i ++)
cin >> a[i];
for (int i = 0; i < n; i ++) {
for (int cn = a[i]; 0 < cn; cn /= 2)
tw[i] += cn % 2;
for (int cn = a[i]; 0 < cn; cn /= 3)
tr[i] += 1 == cn % 3;
}
ll cn = 0;
for (int i = 0; i < n; i ++) {
zero();
cn += go(i, 1ll << i);
}
cout << cn << '\n';
}
Compilation message
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status