Submission #140995

#TimeUsernameProblemLanguageResultExecution timeMemory
140995ShelbyBeautiful row (IZhO12_beauty)C++11
0 / 100
8 ms504 KiB
#include <bits/stdc++.h> using namespace std; int dp[20][1<<20],t[20],b[20],a[20]; bool v[20][20]; 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); //for(i=0;i<n;i++) cout << b[i] << " " << t[i] << endl; return 0; }

Compilation message (stderr)

beauty.cpp: In function 'int main()':
beauty.cpp:10:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d",&n);
 ~~~~~^~~~~~~~~
beauty.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&a[i]);
     ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...