Chinese question test instructions no longer repeat
For this "P" in the middle, we just need to consider the previous
It becomes just a matter of consideration:
That is, two lines before the pressure.
Specifically similar to HDOJ's 4539: see Hdoj 4539
It's just a different judgment of coexistence.
1 //#include <bits/stdc++.h>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7typedefLong LongLL;8 9 intdp[2][1050][1050], mp[ the][ the];Ten intpos[1050], D; One intMain () A { - intD=0; - for(intI=0;i< (1<<Ten); i++) the if(! (i& (i<<2)) &&! (i& (i<<1))) -Pos[d++]=i;//preprocess a row of eligible - intN, M; - while(~SCANF ("%d%d", &n, &m)) + { - intans=0; +Memset (MP,0,sizeof(MP)); A for(intI=1; i<=n;i++) at for(intj=0; j<m;j++) - { - CharC; -Cin>>C; -Mp[i][j]= (c=='P'); - } inMemset (DP,0,sizeof(DP)); - for(intI=1; i<=n;i++)//Enumerate n rows to for(intj=0; J<d && pos[j]< (1<<M); j + +) + { - intsum=0; the for(intk=0; k<m;k++)//for the current (i,k position) whether the row (in front of the K-grid) satisfies * if(pos[j]&1<<k) $sum+=Mp[i][k];Panax Notoginseng for(intk=0; K<d && pos[k]< (1<<M); k++)//enumerate the state of a i-1 row to see if it can coexist with line I - if(! (pos[j]&Pos[k])) the { + inttmp=0; A for(intL=0; L<d && pos[l]< (1<<M); l++)//enumerate the state of i-2 rows to see if they can coexist with line I, line i-1 the if(! (pos[j]&Pos[l])) +Tmp=max (TMP, dp[1-i&1][k][l]); -dp[i&1][j][k]=tmp+sum; $Ans=max (ans, dp[i&1][j][k]); $ } - } -printf"%d\n", ans); the } - return 0;Wuyi}
POJ 1185
[Pressure DP] POJ1185 Artillery Positions