全WA了, 不知道哪里有问题, 大佬求调
#include <bits/stdc++.h>
#define MAXN 110
#define MAXM 15
int a[MAXN][MAXM];
using namespace std;
unordered_map<int, int>hax;
int n, m;
int f[MAXN][(1 << 11) - 1];
inline bool isch(char s){
if (s >= 'A' && s <= 'Z') return 1;
return 0;
}
inline bool check(int x){
if (x & (x << 1)) return false;
if (x & (x << 2)) return false;
if (x & (x >> 1)) return false;
if (x & (x >> 2)) return false;
return true;
}
int lowbit(int x){
return x & (-x);
}
inline bool check2(int x, int line){
while (x){
if (!a[line][m- hax[lowbit(x)]]) return false;
x -= lowbit(x);
}
return true;
}
inline bool check3(int x, int y){
if (x & y) return false;
return true;
}
vector <int> law;
inline int count(int x){
int ans = 0;
while (x){
x -= lowbit(x);
++ans;
}
return ans;
}
int main(){
for (int i = 0; i <= 10; i++){
hax.insert(make_pair(1 << i, i + 1));
}
scanf("%d%d", &n, &m);
char s;
for (int i = 1; i <= n; i++){
for (int p = 1; p <= m; p++){
while (!isch(s = getchar()));
if (s == 'P') a[i][p] = 1;
else a[i][p] = 0;
}
}
int limit = (1 << m) - 1;
for (int i = 1; i <= limit; i++){
if (check(i)) law.push_back(i);
}
for (auto i : law){
if (check2(i, 1)){
f[1][i] = count(i);
}
}
for (int i = 2; i <= 2; i++){
for (auto j : law){
if (check2(j, i)){
int cj = count(j);
for (auto p : law){
if (check2(p, i - 1)){
if (check3(p, j)){
f[i][j] = max(f[i][j], count(p) + cj);
}
}
}
}
}
}
for (int i = 3; i <= n; i++){
for (auto j : law){
if (check2(j, i)){
int cj = count(j);
for (auto p : law){
if (check2(p, i - 1)){
if (check3(p, j)){
int cp = count(p);
for (auto k : law){
if (check2(k, i - 2)){
if (check3(p, k) && check3(k, j))
{
f[i][j] = max(f[i][j], f[i - 2][k] + cp + cj);
}
}
}
}
}
}
}
}
}
int ans = 0;
for (auto j : law){
ans = max(ans, f[n][j]);
}
printf("%d", ans);
}