Salvens

C

Aug 2nd, 2023
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <vector>
  5. #include <array>
  6. #include <set>
  7. #include <map>
  8.  
  9. using namespace std;
  10.  
  11. #define int long long
  12.  
  13. const long long INF = 1e18 + 7;
  14. const int MAXN = 1e1 + 100;
  15. const int N = 3e5 + 10;
  16. const int MOD = 1e9 + 7;
  17.  
  18. int dp[1 << 19];
  19. bool a[18][18];
  20.  
  21. signed main() {
  22.     ios_base::sync_with_stdio(false);
  23.     cin.tie(nullptr);
  24.     cout.tie(nullptr);
  25.  
  26.     freopen("network.in", "r", stdin);
  27.     freopen("network.out", "w", stdout);
  28.    
  29.     int n;
  30.     cin >> n;
  31.     for (int i = 0; i < n; ++i) {
  32.         for (int j = 0; j < n; ++j) {
  33.             char c;
  34.             cin >> c;
  35.             a[i][j] = (c == 'Y' ? 1 : 0);
  36.         }
  37.     }
  38.     for (int mask = 0; mask < (1 << n); ++mask) {
  39.         for (int x = 0; x < n; ++x) {
  40.             if (mask & (1 << x)) continue;
  41.             for (int y = 0; y < n; ++y) {
  42.                 if (mask & (1 << y)) continue;
  43.                 if (a[x][y]) {
  44.                     int new_mask = mask | (1 << x) | (1 << y);
  45.                     dp[new_mask] = max(dp[new_mask], dp[mask] + 2);
  46.                 }
  47.             }
  48.         }
  49.     }
  50.     int ans = 0;
  51.     for (int mask = 0; mask < (1 << n); ++mask) {
  52.         ans = max(ans, dp[mask]);
  53.     }
  54.     cout << ans << '\n';
  55. }
Advertisement
Add Comment
Please, Sign In to add comment