Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我是不知道我这思路 为什么会有错呢,,求大牛搭救

Posted by zzz805 at 2016-05-02 16:46:38 on Problem 1185
/* Author:GavinjouElephant
 * Title:
 * Number:
 * main meanning:
 *
 *
 *
 */

//#define OUT
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <cctype>
#include <vector>
#include <set>
#include <cstdlib>
#include <map>
#include <queue>
//#include<initializer_list>
//#include <windows.h>
//#include <fstream>
//#include <conio.h>
#define MaxN 0x7fffffff
#define MinN -0x7fffffff
#define Clear(x) memset(x,0,sizeof(x))
char Pic[105][20];
int cur[105];
int N,M;
const int maxn=1<<11;
int dp[105][maxn];
int top;
int state[1000];
int geshu[1000];
bool can(int x)
{
    if(x&(x<<1))return false;
    if(x&(x<<2))return false;
    return true;
}
int Count(int x)
{
    int ans=0;
    while(x)
    {
        ans++;
        x&=(x-1);
    }
    return ans;
}
void init()
{
    top=0;
    for(int i=0;i<(1<<M);i++)
    {
        if(can(i))
        {
            state[top]=i;
            geshu[top++]=Count(i);
        }
    }
}
bool fit(int x,int row)
{
    if(x&cur[row])return false;
    return true;
}

int main()
{
#ifdef OUT
    freopen("coco.txt","r",stdin);
    freopen("lala.txt","w",stdout);
#endif
   while(scanf("%d%d",&N,&M)!=EOF)
   {
       if(N==0&&M==0)break;
       memset(dp,0,sizeof(dp));
       init();
       for(int i=0;i<N;i++)
        scanf("%s",Pic[i]);
       for(int i=0;i<N;i++)
       {
           int k=0;
           for(int j=M-1;j>=0;j--)
           {
                if(Pic[i][j]=='H')k+=(1<<j);
           }
           cur[i]=k;
       }
       if(N>=1)
       {
           for(int i=0;i<top;i++)
           {
              if(fit(state[i],0)) dp[0][state[i]]=geshu[i];
           }
       }
       if(N>=2)
       {
           for(int i=0;i<top;i++)
           {
               if(!fit(state[i],1))continue;
               for(int j=0;j<top;j++)
               {
                   if(!fit(state[j],0))continue;
                   if(state[i]&state[j])continue;
                   dp[1][state[i]]=max(dp[1][state[i]],geshu[j]+geshu[i]);
               }
           }
       }
       if(N>=3)
       {
           for(int i=2;i<N;i++)//行数
           {
               for(int j=0;j<top;j++)//枚举当前行当前状态可不可以
               {
                    if(!fit(state[j],i))continue;
                    for(int k=0;k<top;k++)//枚举前一行的状态可不可以
                    {
                         if(!fit(state[k],i-1))continue;
                         if(state[j]&state[k])continue;
                         for(int l=0;l<top;l++)//枚举前前一行的状态可不可以
                         {
                             if(!fit(state[l],i-2))continue;
                             if(state[k]&state[l])continue;
                             if(state[j]&state[l])continue;
                             dp[i][state[j]]=max(dp[i][state[j]],dp[i-2][state[l]]+geshu[k]+geshu[j]);
                         }
                    }
               }
           }
       }

       int ans=0;
       for(int j=0;j<top;j++)
       {
           if(!fit(state[j],N-1))continue;
           ans=max(ans,dp[N-1][state[j]]);
       }
       printf("%d\n",ans);

   }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator