Submission #106206

#TimeUsernameProblemLanguageResultExecution timeMemory
106206HideoBeautiful row (IZhO12_beauty)C++14
0 / 100
16 ms2944 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mk make_pair #define fr first #define sc second #define vi vector < int > #define vl vector < ll > #define pi pair < int, int > #define pii pair < int, pi > #define vii vector < pi > const int N = 1e5 + 7; const int mod = 1e9 + 7; int b[20], t[20]; int n; ll dp[(1 << 20)][20]; ll ans; int bin (int x, int c = 0){ if (x % 2 == 1) c++; if (!x) return c; bin(x / 2, c); } int ter (int x, int c = 0){ if (x % 3 == 1) c++; if (!x) return c; ter(x / 3, c); } main(){ cin >> n; for (int i = 0; i < n; i++){ int a; cin >> a; b[i] = bin(a); t[i] = ter(a); } for (int i = 0; i < n; i++) dp[(1 << i)][i] = 1; for (int val = 2; val <= n; val++){ for (int mask = 1; mask < (1 << n); mask++){ int cnt = 0; for (int sub = 0; sub < n; sub++) if (mask & (1 << sub)) cnt++; if (cnt != val) continue; for (int sub = 0; sub < n; sub++){ if (mask & (1 << sub)){ int submask = (mask ^ (1 << sub)); for (int last = 0; last < n; last++) if (last != sub && submask & (1 << last) && (b[last] == b[sub] || t[last] == t[sub])) dp[mask][sub] += dp[submask][last]; dp[mask][sub] %= mod; } } } } int mask = 0; for (int i = 0; i < n; i++) mask += (1 << i); for (int last = 0; last < n; last++) ans += dp[mask][last]; cout << ans % mod; }

Compilation message (stderr)

beauty.cpp:40:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
beauty.cpp: In function 'int bin(int, int)':
beauty.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
beauty.cpp: In function 'int ter(int, int)':
beauty.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...