fork download
  1. // ~~ icebear love atttt ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int MOD = 1e9 + 7;
  6. const int inf = 1e9 + 27092008;
  7. const long long INF = 1e18 + 27092008;
  8. const int N = 1020 + 5;
  9. int n, v[N];
  10. char cur[N], res[N];
  11. int ans;
  12. bitset<N> vis[1 << 3][201][N];
  13. struct State {
  14. int i, j, k, mask;
  15. };
  16. queue<State> states;
  17.  
  18. void dfs(int mask, int i, int x, int y, int z) {
  19. if (i == n) {
  20. if (mask == (1 << 3) - 1 && ans < x + y + z) {
  21. ans = x + y + z;
  22. for(int i = 0; i < n; i++) res[i] = cur[i];
  23. }
  24. return;
  25. }
  26. if (vis[mask][i][x][y]) return;
  27. vis[mask][i][x][y] = true;
  28. cur[i] = 'P';
  29. dfs(mask | (1 << 0), i + 1, x ^ v[i], y, z);
  30. cur[i] = 'V';
  31. dfs(mask | (1 << 1), i + 1, x, y ^ v[i], z);
  32. cur[i] = 'H';
  33. dfs(mask | (1 << 2), i + 1, x, y, z ^ v[i]);
  34. }
  35.  
  36. int main() {
  37. #define task "chemistry"
  38. if (fopen(task".inp", "r")) {
  39. freopen(task".inp", "r", stdin);
  40. freopen(task".out", "w", stdout);
  41. }
  42. ios_base::sync_with_stdio(0);
  43. cin.tie(0); cout.tie(0);
  44. int subtask; cin >> subtask;
  45. while(cin >> n) {
  46. if (!n) break;
  47. for(int i = 0; i < n; i++) cin >> v[i];
  48. memset(vis, false, sizeof vis);
  49. ans = -1;
  50. dfs(0, 0, 0, 0, 0);
  51. for(int i = 0; i < n; i++)cout << res[i];
  52. cout << '\n';
  53. }
  54. return 0;
  55. }
  56.  
  57.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty