# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
140994 | Shelby | Beautiful row (IZhO12_beauty) | C++11 | 7 ms | 504 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dp[21][1<<20],t[21],b[21],a[21];
bool v[21][21];
int main()
{ int n,i,j,x,tmp,mask,sol=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
b[i]=__builtin_popcount(a[i]);
x=a[i];
while(x>0)
{
tmp=x%3;
if(tmp==1) t[i]++;
x=x/3;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((b[i]==b[j] || t[i]==t[j]) && i!=j) v[i][j]=true;
}
}
for(i=0;i<n;i++) dp[(1<<i)][i]=1;
for(mask=0;mask<(1<<n);mask++)
{
for(i=0;i<n;i++)
{
if(mask&(1<<i))
{
for(j=0;j<n;j++)
{
if( (mask&(1<<j))==0 && v[i][j]==true )
{
dp[mask|(1<<j)][j]+=dp[mask][i];
}
}
}
}
}
for(i=0;i<n;i++) sol+=dp[(1<<n)-1][i];
printf("%d\n",sol);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |