제출 #1121446

#제출 시각아이디문제언어결과실행 시간메모리
1121446ezzzay아름다운 순열 (IZhO12_beauty)C++14
0 / 100
7 ms1816 KiB
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back const int N=3e5+5; int a[N]; int bincnt(int n){ int p=0; while(n>0){ p+=n%2; n/=2; } return p; } int tercnt(int n){ int p=0; while(n>0){ if(n%3==1)p++; n/=3; } return p; } int bc[N],tc[N]; int dp[1048590][21]; signed main(){ int ans=0; int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; bc[i]=bincnt(a[i]); tc[i]=tercnt(a[i]); } for(int i=0;i<n;i++){ dp[(1<<i)][i]=1; } for(int i=1;i<(1<<n);i++){ for(int a=0;a < n;a++){ if(i & (1<<a)){ // umnuhd ni orsn for(int b=0;b<n;b++){ if(tc[b]!=tc[a] and bc[a]!=bc[b])continue; if(((1<<b) & i) == 0){ dp[i | (1<<b)][b] = (dp[i|(1<<b)][b] + dp[i][a]) ; } } } } } for(int i=0;i<n;i++){ ans+=dp[(1<<n)-1][i]; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...