POJ 1185 Artillery

Source: Internet
Author: User

is the Chinese title. We all say water problem. But, good 1A it?

Title Effect:

Given the n*m matrix, when a cell has an artillery unit its upper and lower left and right sides (not including the oblique direction) is the attack range of this force. It is not possible for the two armies to attack each other. The maximum number of artillery units that can be deployed.


Problem Solving Ideas:
State compression Dp,dp[i][j][k] represents when line I is the state of J. The maximum number of artillery is arranged when the i-1 is in the K state.

Status can be pre-processed, there are only 60 kinds.



Here's the code:

#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <    Stdlib.h>using namespace Std;int min (int a,int b) {if (a>b) a=b; return A;}    int max (int a,int b) {if (a<b) a=b; return A;}    int n,m,vaild[65],cn[65],cnt;void judge () {int p,num;    cnt=0; for (int i=0; i<1<<10; i++) {if ((i<<1) &i) | |        ((i<<2) &i))        {continue;        } int temp=i;            while (temp) {if (temp%2) cn[cnt]++;        temp>>=1;    } vaild[cnt++]=i;    }}int Place[105];char s[15];int dp[105][65][65];int Main () {judge ();        while (scanf ("%d%d", &n,&m)!=eof) {int ans=0;            for (int i=1; i<=n; i++) {scanf ("%s", s);            place[i]=0;                for (int j=0; j<m; J + +) {place[i]<<=1;               if (s[j]== ' H ') {place[i]++; }}} memset (Dp,0,sizeof (DP)); for (int i=1, i<=n; i++) {if (i==1) {for (int j=0; vaild[j]<1<<m&am p;&j<cnt; J + +) {if ((Place[1]&vaild[j]) ==0) {dp[1][                    J][0]=CN[J];                } ans=max (Ans,dp[1][j][0]);  }} else if (i==2) {for (int j=0; vaild[j]<1<<m&&j<cnt; J + +) {if ((Place[2]&vaild[j]) ==0) {for (i NT K=0; vaild[k]<1<<m&&k<cnt; k++) {if ((vaild[k]&vaild[j)) ==0&& (Place[1]&vaild[k]) ==0                            ) {Dp[2][j][k]=dp[1][k][0]+cn[j]; } Ans=max (ans,dp[2][j][k]); }}}} else {for (int j=0; vaild[j]< 1<<m&&j<cnt; J + +) {if ((Place[i]&vaild[j]) ==0) {for (in T k=0; vaild[k]<1<<m&&k<cnt; k++) {if ((Vaild[k]&vaild[j]) ==0&& (place[i-1]&vaild[k]) =                                =0) {for (int l=0;vaild[l]<1<<m&&l<cnt;l++) {if ((Vaild[k]&vaild[l]) ==0&& (vaild[j]&v                                        Aild[l]) ==0&& (Place[i-2]&vaild[l]) ==0) {                                    Dp[i][j][k]=max (Dp[i][j][k],dp[i-1][k][l]+cn[j]);   }                                }                            }                         Ans=max (Ans,dp[i][j][k]);    }}}}} printf ("%d\n", ans); } return 0;}


POJ 1185 Artillery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.