题意很简单,题目也很水
唯一一个容易忽略的地方就是状态数其实没有看起来的那么多,因为有一个攻击范围的限制所以状态数其实很少。
然后,脑残的又把数据范围开小了。。。。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#define N (1<<9)+(1<<6)+(1<<3)+1+10
int map[210],f[3][N][N];
int q[N];
int n,m,qtail;
using namespace std;
void input()
{
char ch=0;
scanf("%d %d ",&n,&m);
for (int i=1;i<=n;i++)
{
map[i]=0;
for (int j=1;j<=m;j++)
{
scanf("%c",&ch);
if (ch=='P') map[i]=(map[i]<<1)+1;
else map[i]=map[i]<<1;
}
scanf("\n");
}
}
void pre_work()
{
memset(q,0,sizeof(q));
qtail=0;
for (int i=0;i<=(1<<m)-1;i++)
{
int now=i;
bool flag=true;
while (now)
{
while (now%2==0) now=now>>1;
if (((now&1)==1)&&((now&2)==2)) {flag=false;break;}
if (((now&1)==1)&&((now&4)==4)) {flag=false;break;}
now=now>>1;
}
if (flag==true) q[++qtail]=i;
}
}
int count(int x)
{
int now=0;
while (x)
{
if ((x&1)==1) now++;
x=x>>1;
}
return now;
}
void work()
{
int ans=0;
memset(f,0,sizeof(f));
for (int i=1;i<=n;i++)
{
for (int j=1;j<=qtail;j++)
{
if (q[j]==585)
{
ans=ans;
}
if ((q[j]|map[i])!=map[i])
{
for (int k=1;k<=qtail;k++)
f[1][k][j]=0;
continue;
}
for (int k=1;k<=qtail;k++)
for (int l=1;l<=qtail;l++)
{
if ((i==1)&&(q[k]>0||q[l]>0)) break;
if ((i==2)&&(q[k]>0)) break;
if ((q[j]&q[k])!=0) continue;
if ((q[j]&q[l])!=0) continue;
if ((q[l]&q[k])!=0) continue;
f[1][q[l]][q[j]]=max(f[1][q[l]][q[j]],f[0][q[k]][q[l]]+count(q[j]));
}
}
for (int j=1;j<=qtail;j++)
for (int k=1;k<=qtail;k++)
{
int now1=q[j],now2=q[k];
f[0][now1][now2]=f[1][now1][now2];
f[1][q[j]][q[k]]=0;
ans=max(ans,f[0][q[j]][q[k]]);
}
}
printf("%d",ans);
}
int main()
{
input();
pre_work();
work();
return 0;
}
嘛,积题有点多慢慢做完吧,尽量这个假期过完积题清理完