# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
339843 | nandonathaniel | Beautiful row (IZhO12_beauty) | C++14 | 859 ms | 164460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN=20;
int n;
long long dp[1<<MAXN][MAXN];
int a[MAXN],binary[MAXN],ternary[MAXN];;
int basetwo(int x){
return __builtin_popcount(x);
}
int basethree(int x){
int ret=0;
while(x>0){
if(x%3==1)ret++;
x/=3;
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i=0;i<n;i++){
cin >> a[i];
dp[1<<i][i]=1;
binary[i]=basetwo(a[i]);
ternary[i]=basethree(a[i]);
}
for(int i=1;i<(1<<n);i++){
for(int j=0;j<n;j++){
if((1<<j) & i){
for(int k=0;k<n;k++){
if(!((1<<k) & i)){
if(binary[k]==binary[j] || ternary[k]==ternary[j])dp[i+(1<<k)][k]+=dp[i][j];
}
}
}
}
}
long long ans=0;
for(int i=0;i<n;i++)ans+=dp[(1<<n)-1][i];
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |