[Explanations] artillery site preparation

[Explanations] artillery site preparation

luogu

answer

Violence-like pressure on the line and record information on the uplink, violent determine whether there is not a legitimate position, rolling array violence, violence statistics, violence can be transferred.

Read yyb code, I feel I have not written the code ...

Join say do not be so violent can also be useful to know the real state is very small, you can directly search plus pruning itself of this problem is NP.

//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>


using namespace std;  typedef long long ll;
inline int qr(){
      register int ret=0,f=0;
      register char c=getchar();
      while(c<48||c>57)f|=c==45,c=getchar();
      while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
      return f?-ret:ret;
}
int f[2][1<<10][1<<10];
int n,m,way[110],ans;
int nex[1<<10];
int main(){
      n=qr();m=qr();
      char ch[50];
      for(register int i=1;i<=n;++i){
        scanf("%s",ch+1);
        for(int j=1;j<=m;++j)
          way[i]|=(ch[j]=='P')<<(j-1);
      }
      for(register int t=(1<<m)-1,last=-1;t>=0;--t){
        if(((t<<1)|(t<<2)|(t>>1)|(t>>2))&t)continue;
        nex[t]=last;last=t;
      }
      for(register int i=1;i<=n;++i){
        for(register int t=0;t<1<<10;++t)
          for(register int k=0;k<1<<10;++k)
            f[i&1][t][k]=0;
        for(register int j=0;j!=-1;j=nex[j]){
          if(i==1&&j!=0)break;
          if(i!=1&&i!=2)if((j&way[i-2])!=j)continue;
          for(register int k=0;k!=-1;k=nex[k]){
            if(k&j)continue;
            if(i!=1&&(k&way[i-1])!=k)continue;
            for(register int l=0;l!=-1;l=nex[l]){
                  if((k|j)&l)continue;
                  if((l&way[i])!=l)continue;
                  register int tol=0,temp=l;
                  while(temp)tol++,temp-=temp&(-temp);
                  ans=max(ans,f[i&1][k][l]=max(f[i&1][k][l],f[(i-1)&1][j][k]+tol));
            }
          }
        }
      }
      cout<<ans<<endl;
      return 0;
}

Guess you like

Origin www.cnblogs.com/winlere/p/10990786.html