Advertisement
Mirbek

D - Dance (Atcoder)

Jan 28th, 2022
704
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 17;
  6.  
  7. int n, ans = 0;
  8. int A[N][N], used[N];
  9.  
  10. void rec(int couples, int xr) {
  11.     if (couples == n) {
  12.         ans = max(ans, xr);
  13.         return;
  14.     }
  15.  
  16.     int i = 1;
  17.     while (used[i]) i++;
  18.  
  19.     for (int j = i + 1; j <= 2 * n; j++) {
  20.         if (used[j] == 0) {
  21.             used[i] = used[j] = 1;
  22.             rec(couples + 1, xr ^ A[i][j]);
  23.             used[i] = used[j] = 0;
  24.         }
  25.     }
  26. }
  27.  
  28. int main(){
  29.     cin >> n;
  30.  
  31.     for (int i = 1; i <= 2 * n; i++) {
  32.         for (int j = i + 1; j <= 2 * n; j++) {
  33.             cin >> A[i][j];
  34.         }
  35.     }
  36.  
  37.     rec(0, 0);
  38.  
  39.     cout << ans << endl;
  40. }
  41.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement