[2704] artillery Luo Valley

Title Description

Command generals intend to deploy their artillery on a grid map of N * M. N * M is a map consisting of N rows and M columns, each cell may be mountain map (indicated by "H"), it may be plain (indicated by "P"), as shown below. It can be arranged on each cell up to a plain terrain artillery (not to deploy artillery on the mountain); a range artillery attack on a map as shown in the black area below:

If the deployment of an artillery plain gray map identified, the figure represents a black grid to a region that can attack: two each along the left and right lateral frame, two cells up and down in the longitudinal direction. The figure was not attack other white grid. Visible effects of artillery attacks against a range of terrain from the map. Now, the generals were planning how to deploy artillery, under the premise of preventing accidental injury (guarantee not attack each other between any two artillery units, that is, any one artillery unit is not within the scope of the attack other artillery support) throughout the map the maximum number of the army's artillery units can be placed in the area.

Input Format

The first line contains two open spaces separated by positive integers M and N, respectively;

The next N rows, each row comprising M consecutive characters ( 'P' or 'H'), with no spaces. Order data representing a map of each line. N≤100; M≤10.

Output Format

Only one line contains an integer K, it represents the number up to the placing of artillery.

Sample input and output

Input # 1
5 4 
PHPP 
PPHH 
PPPP 
PHPP 
PHHP
Output # 1
6 

problem solution: boom, the story of a comma and semicolon pit me half an hour awsl
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
const int b[15] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192};
 Int OP, n-, m, ANS, CNT, A [ 105 ], S [ 100 ], Ki [ 100 ], DP [ . 3 ] [ 70 ] [ 70 ];
 // DP [I] [J] [K ] ==> state i-th row j, the state of line K 
char C [ 15 ];
 int Boom ( int X) {  
     int KII = 0 ;
     the while (X) 
      KII + X% = 2 , X = >> . 1 ;
     return KII; 
} 

void the init () { 
      for ( int I = 0 ; I <OP; I ++){
         if(i&(i>>1)) continue;
         if(i&(i<<1)) continue;
         if(i&(i>>2)) continue;
         if(i&(i<<2)) continue;
         cnt++; s[cnt]=i;
         ki[cnt]=boom(i);
     }
}

void work(){ 
    for(int i=1;i<=cnt;i++) 
        if((s[i]|a[1])==a[1])
            dp[1][i][0]=ki[i];
    for(int i=1;i<=cnt;i++)
        for(int j=1;j<=cnt;j++) 
            if((s[i]|a[2])==a[2]&&(s[j]|a[1])==a[1]&&(s[i]&s[j])==0)
                dp[2][i][j] = ki[i] + ki[j];
    for(int i=3;i<=n;i++)//当前行 
        for( Int J = . 1 ; J <= CNT; J ++) // at the current line 
            IF ((S [J] | A [I]) == A [I])
                 for ( int K = . 1 ; K <= CNT ; K ++) // the line state 
                    IF ((S [K] | a [I- . 1 ]) == a [I- . 1 ] && (! (S [J] & S [K]))) 
                         for ( int L = . 1 ; L <= CNT; L ++) // state up the second row 
                            IF ((S [L] | a [I- 2 ]) == a [I- 2 ] && (S [J! ] & S [L]) &&! (S [K] & S [L])) 
                                DP [I % . 3][j][k] = max(dp[i%3][j][k], dp[(i-1)%3][k][l]+ki[j]);    
}
int main(){
    freopen("2704.in","r",stdin);
    freopen("27044.out","w",stdout);
    scanf("%d %d",&n,&m);
    op=(1<<m)-1;
    for(int i=1;i<=n;i++){
        scanf("%s",c+1);
        for(int j=1;j<=m;j++){
            a[i]<<=1;
            if(c[j]=='P') a[i] += 1;
        }
    }
    init(); 
    work();
    for(int i=1;i<=cnt;i++) 
        for(int j=1;j<=cnt;j++) 
            ans=max(ans,dp[n%3][i][j]);
    printf("%d\n", ans);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11332734.html