# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90268 | Aydarov03 | Beautiful row (IZhO12_beauty) | C++14 | 1484 ms | 205876 KiB |
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 <bits/stdc++.h>
using namespace std;
const int N = 25;
int b[N] , t[N] , x;
long long dp[ (1 << 20) + 7][N] , ans;
bool can[N][N];
int cnt( int x , int k )
{
int res = 0;
while( x > 0 )
{
res += ( x % k == 1 );
x /= k;
}
return res;
}
main()
{
int n , x;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> x;
b[i] = cnt( x , 2 );
t[i] = cnt( x , 3 );
}
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if( b[i] == b[j] || t[i] == t[j] )
can[i][j] = can[j][i] = 1;
for(int i = 0; i < n; i++)
dp[ (1 << i) ][i] = 1;
for(int mask = 1; mask < (1 << n) - 1; mask++)
{
for(int last = 0; last < n; last++)
{
if( mask & ( 1 << last ) == 0 )continue;
for(int nxt = 0; nxt < n; nxt++)
{
if( mask & ( 1 << nxt ) || can[last][nxt] == false )
continue;
dp[ mask + ( 1 << nxt ) ][nxt] += dp[mask][last];
}
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
}
}
for(int i = 0; i < n; i++)
ans += dp[ (1 << n) - 1 ][i];
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |