Rick15999640961 @ 2025-01-11 18:47:46
20分求调
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,k,dp[108][1<<10][1<<10],dis[1<<10],num[1<<10],cnt,d[14];
void haha(){
for(int i=0;i<(1<<m);i++)
if(!(i&i>>1) && !(i&i>>2)){
dis[cnt++]=i;
for(int j=0;j<m;j++)
num[i]+=(i>>j&1);
}
}
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
char o;
for(int j=0;j<m;j++){
cin>>o;
if(o=='P')d[i]+=1<<(m-j-1);
}
}
haha();
for(int i=1;i<=n+2;i++){
for(int a=0;a<cnt;a++){
for(int b=0;b<cnt;b++){
for(int c=0;c<cnt;c++){
if(!(dis[a]&dis[b])&&!(dis[a]&dis[c])&&!(dis[b]&dis[c])&&(d[i]&dis[a])==dis[a]&&(d[i-1]&dis[b])==dis[b])
dp[i][a][b]=max(dp[i][a][b],dp[i-1][b][c]+num[dis[a]]);
}
}
}
}
cout<<dp[n+2][0][0];
return 0;
}
by tangzirui1016 @ 2025-01-11 18:50:35
@Rick15999640961 d数组开小了
by Rick15999640961 @ 2025-01-11 18:59:16
果乐 谢