Analysis: First enumerate all the legal state (when n=10 the legal state up to 60), with the current state to match the state of the previous row and the upper line to match, to see if it can .... Complexity is 100*60*60*60, and can be accepted.
The code is as follows:
=============================================================================================================== ==========
#include <stdio.h>#include<algorithm>#include<string.h>using namespacestd;Const intMAXN =107;Const intMAXM = the;intDP[MAXN][MAXM][MAXM];intHaveone (intXintN) { ints[maxn]={0}, sum=0; for(inti=n-1; i>=0; i--) {S[i]= (x&1); X>>=1; if(S[i] && (s[i+1] || s[i+2])) return-1; if(S[i]) sum++; } returnsum;}intMain () {intM, N; while(SCANF ("%d%d", &m, &n)! =EOF) { CharS[MAXN]; intdata[maxn]={0}, NONE[MAXM], BIT[MAXM], cnt=0; for(intI=0; i< (1<<N); i++) {none[cnt]=Haveone (i, N); if(none[cnt]! =-1) {bit[cnt++] =i; } } for(intI=2; i<=m+1; i++) {scanf ("%s", s); for(intj=0; j<n; J + +) Data[i]= data[i]*2+ (s[j]=='P'?0:1); } memset (DP,false,sizeof(DP)); intans=0; for(intt=2; t<=m+1; t++) { for(intI=0; i<cnt; i++)if( ! (Bit[i] &Data[t])) for(intj=0; j<cnt; J + +)if( ! (Bit[j] & data[t-1]) ) for(intk=0; k<cnt; k++)if( ! (Bit[k] & data[t-2]) ) { if(! (Bit[i] & Bit[j]) &&! (Bit[j] & Bit[k]) &&! (Bit[i] &Bit[k])) {Dp[t][i][j]= Max (Dp[t][i][j], dp[t-1][j][k]+None[i]); Ans=Max (ans, dp[t][i][j]); }}} printf ("%d\n", ans); } return 0;}
Artillery positions-POJ 1185 (state compression)