Artillery position POJ 1185

Source: Internet
Author: User

N*m

P and M

P can put a man m not

People can't call each other to ask how many people they can put up.

#include <stdio.h>#include<algorithm>#include<string.h>#include<math.h>#include<map>using namespacestd;#defineMAXN 1<<10Charz[ the][ the];intx[ the];intdp[ the][ $][ $];intnum[ $];intcn[ $];intCount (inta) {    intans=0;  while(a>0)    {        if(a&1) ans++; A=a>>1; }    returnans;}intMain () {intn,m;  while(SCANF ("%d%d", &n,&m)! =EOF) {         for(intI=0; i<n;i++) scanf ("%s", Z[i]); memset (x,0,sizeof(x)); Memset (DP,-1,sizeof(DP)); intCnt=0; inten=1<<m;  for(intI=0; i<en;i++)            if((i& (i<<2))|| (i& (i<<1)))==0) {cn[cnt]=Count (i); Num[cnt++]=i; }         for(intI=0; i<n;i++)        {             for(intj=0; j<m;j++)                if(z[i][j]=='H') X[i]|=(1<<j); }         for(intI=0; i<cnt;i++)        {            if(x[0]&Num[i])Continue; dp[0][i][0]=Cn[i]; }         for(intI=1; i<n;i++)//Line        {             for(intj=0; j<cnt;j++)//The state of this line            {                if(x[i]&num[j])//cannot contradictContinue;  for(intk=0; k<cnt;k++)//the state of the previous row                {                    if(num[j]&num[k])//Adjacent two lines cannot appear simultaneously 1Continue;  for(intk1=0; k1<cnt;k1++)//The second line above the state                    {                        if(num[j]&NUM[K1])//Adjacent two lines cannot appear simultaneously 1Continue; if(dp[i-1][k][k1]==-1)                            Continue; DP[I][J][K]=max (dp[i][j][k],dp[i-1][k][k1]+Cn[j]); }                }            }        }        intans=0;  for(intI=0; i<cnt;i++)             for(intj=0; j<cnt;j++) ans=max (dp[n-1][i][j],ans); printf ("%d\n", ans); }    return 0;}

Artillery position POJ 1185

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.