#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "
#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb push_back
ll getVal(int x, int t){
ll cnt = 0;
while(x) {
ll p = x%t;
if(p == 1)
++cnt;
x /= t;
}
return cnt;
}
bool special(int x, int y) {
if(getVal(x, 2) == getVal(y, 2))
return true;
if(getVal(x, 3) == getVal(y, 3))
return true;
return false;
}
void solve()
{
int n;
cin >> n;
vi a(n);
for(auto &i : a)
cin >> i;
ll dp[(1<<n)][n] = {};
FOR(i, 0, n)
dp[(1<<i)][i] = 1;
FOR(i, 0, (1<<n)) {
FOR(j, 0, n) {
if(!(i & (1<<j)))
continue;
ll prev = i ^ (1<<j);
FOR(k, 0, n) {
if(special(k, j))
dp[i][j] += dp[prev][k];
}
}
}
ll ans = 0;
for(auto i : dp[(1<<n) - 1]) ans += i;
cout << ans << nl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |