HDU 4539 Director Zheng's series of stories

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4539

Director Zheng's series of stories

Time Limit: 10000/5000 MS (Java/others) memory limit: 65535/32768 K (Java/Others)
Total submission (s): 1708 accepted submission (s): 620


Problem description Director Zheng is not Director Zheng
Or vice director
He is not the director at all.
In fact
He is the head of the army

One day, Director Zheng took his army to a plain where N * m was prepared.
Based on past combat experience, each soldier can attack and attack only the location 2 from the Manhattan and the location of the soldiers themselves. Of course, a soldier cannot stand where another soldier can attack, and not every position on the plain can arrange soldiers for Terrain reasons.
Now, we know the specific terrain of n, m and plain positions. Please help Director Zheng calculate the positions and arrange at most a number of soldiers.

 

The input contains multiple groups of test data;
The first row of each data group contains two integers, N and M (n <= 100, m <= 10), separated by spaces;
In the next n rows, the number of M lines indicates the rectangular positions of N * M. 1 indicates that soldiers can be arranged at the position, and 0 indicates that soldiers cannot be arranged on the terrain.

 

Calculate and output the maximum number of soldiers that can be arranged for each group of data, and output one row of data for each group.

 

Sample input6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

 

Sample output2

Analysis: the distance from Manhattan is 2, one meter, and the point is the center. The distance is 2. Just change it like poj1181. Increase the size of the array. Int DP [102] [202] [202];

Array opened too small, always wa, sad

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int dp[102][202][202];int n,m,p,sta[4096],sum[4096];int count(int n) {     int num = 0;     while(n){        n &= (n - 1);        num++;       }     return num; }void init(){    int i;    for(i=0;i<1<<m;i++)    {        if((i<<2)&i)           continue;         sum[p]=count(i);        sta[p++]=i;    }}int fit(int x,int y){    if(x&y)       return 0;    else       return 1;}int match(int x,int y){    if((x<<1)&y)        return 0;     if(x>>1&y)        return 0;    return 1;} int main() {      int i,j,a[105],tem,k,r;      while(~scanf("%d%d",&n,&m))      {               p=0;           memset(dp,-1,sizeof(dp));            memset(a,0,sizeof(a));            memset(sta,0,sizeof(sta));            memset(sum,0,sizeof(sum));          for(i=1;i<=n;i++)          {            for(j=1;j<=m;j++)            {                scanf("%d",&tem);                if(tem==0)                     a[i]+=1<<m-j;            }          }       init();        for(i=0;i<p;i++)        {            if(fit(sta[i],a[1]))              {                  dp[1][i][0]=sum[i];              }        }     for(i=2;i<=n;i++)        {            for(j=0;j<p;j++)             {                 if(!fit(sta[j],a[i]))                    continue;                 for(k=0;k<p;k++)                   {                       if(!fit(sta[k],a[i-1]))                          continue;                      if(!match(sta[j],sta[k]))                           continue;                           for(r=0;r<p;r++)                          {                                if(!fit(sta[r],sta[j]))                                    continue;                               if(!fit(sta[r],a[i-2]))                                  continue;                             if(!match(sta[k],sta[r]))                                 continue;                               dp[i][j][k]=max(dp[i][j][k],dp[i-1][k][r]+sum[j]);                          }                   }             }        }          int ans=0;        for(i=0;i<p;i++)          for(j=0;j<p;j++)         {             ans=max(ans,dp[n][i][j]);         }         printf("%d\n",ans);      }      return 0; }

 

 

 

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.