Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <array>
- #include <set>
- #include <map>
- using namespace std;
- #define int long long
- const long long INF = 1e18 + 7;
- const int MAXN = 1e1 + 100;
- const int N = 3e5 + 10;
- const int MOD = 1e9 + 7;
- int dp[1 << 19];
- bool a[18][18];
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- freopen("network.in", "r", stdin);
- freopen("network.out", "w", stdout);
- int n;
- cin >> n;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- char c;
- cin >> c;
- a[i][j] = (c == 'Y' ? 1 : 0);
- }
- }
- for (int mask = 0; mask < (1 << n); ++mask) {
- for (int x = 0; x < n; ++x) {
- if (mask & (1 << x)) continue;
- for (int y = 0; y < n; ++y) {
- if (mask & (1 << y)) continue;
- if (a[x][y]) {
- int new_mask = mask | (1 << x) | (1 << y);
- dp[new_mask] = max(dp[new_mask], dp[mask] + 2);
- }
- }
- }
- }
- int ans = 0;
- for (int mask = 0; mask < (1 << n); ++mask) {
- ans = max(ans, dp[mask]);
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment