topic:
Resolution:
And as non-aggression
is more of a grid
with \ (f [i] [j ] [k] \) represents the i-th row, the row state \ (J \) , uplink state \ (K \) of the most you can put the artillery
found \ (100 \ times 1024 \ times 1024 \) to open no less
or even found by a simple search \ (m == 10 \) legal status only when \ (60 \) species
\ (100 \ times 60 \ times 60 \) , no problem
then and as non-aggression, the state can be enumerated a
state transition
\ (f [i] [j ] [k] = max \ {f [i] [j] [K], F [I-1] [K] [L] + SUM [state [I]] \} \)
\ (SUM [I] \) represents \ (I \) states how many \ (1 \)
Code:
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m, num, ans = -0x3f3f3f3f;
int state[N], sum[1050], line[N], f[N][N][N];
char s[N];
int qpow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1) ans = ans * a;
a *= a, b >>= 1;
}
return ans;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> s;
for (int j = m - 1; j >= 0; --j)
if (s[j] == 'P') line[i] += qpow(2, m - j - 1);
}
for (int i = 0; i < (1 << m); ++i) {
if ((i & (i << 1)) || (i & (i >> 1)) ||
(i & (i << 2)) || (i & (i >> 2))) continue;
state[++num] = i;
sum[i] = __builtin_popcount(i);
}
for (int i = 1; i <= num; ++i)
if ((state[i] | line[1]) == line[1])
f[1][i][1] = sum[state[i]];
for (int i = 2; i <= n; ++i)
for (int j = 1; j <= num; ++j)
if ((state[j] | line[i]) == line[i])
for (int k = 1; k <= num; ++k)
if ((state[k] | line[i - 1]) == line[i - 1] && !(state[j] & state[k]))
for (int l = 1; l <= num; ++l)
if (!(state[l] & state[k]) &&
!(state[l] & state[j]) &&
(state[l] | line[i - 2]) == line[i - 2])
f[i][j][k] = max(f[i][j][k], f[i - 1][k][l] + sum[state[j]]);
for (int i = 1; i <= num; ++i)
for (int j = 1; j <= num; ++j)
ans = max(ans, f[n][i][j]);
cout << ans;
}