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

where is wrong ??

Posted by hdu07021 at 2007-08-20 04:11:30 on Problem 2724
#include<iostream>
using namespace std;
bool map[1001][1001];
int visit[1024];
int visit1[1024];
int match[1024];
int visit2[1024];
int n,m;
char str[11];
int state[1024];
bool hash[1024];
int r[1024];
int l;
bool dfs(int k)
{
	int i;
	for(i=0;i<m;i++)
	{
		if(map[k][i]&&!visit2[i])
		{
			visit2[i]=1;
			int t=match[i];
			match[i]=k;
			if(t==-1||dfs(t))
				return true;
			match[i]=t;
		}
	}
	return false;
}
bool compare(int a,int b ,int n)
{
   int c[11];
   int d[11];
   int i=0,count=0;
   for(i=0;i<n;i++)
   {
	   c[i]=a%2;
	   a/=2;
	   d[i]=b%2;
	   b/=2;
	   if(c[i]!=d[i])
		   count++;
   }
   if(count<=1)
	   return true;
   else 
	   return false;
}
int main()
{
    int N,s,i,j;	
	while(scanf("%d %d",&N,&s)&&N+s)
	{
		memset(visit,0,sizeof(visit));
		memset(visit1,0,sizeof(visit1));
		memset(state,0,sizeof(state));
		memset(hash,0,sizeof(hash));
		memset(map,0,sizeof(map));
		l=0;
		for(i=0;i<s;i++)
		{
			scanf("%s",&str);
			int p=-1;
			for(j=0;j<N;j++)
			{
               if(str[j]=='*')
			   {
				   p=j;
				   continue;
			   }
			   state[l]+=(str[j]-'0')*(1<<(N-j-1));
			}
			if(p!=-1)
			{
				l++;
				state[l]=state[l-1]|(1<<(N-p-1));
				if(!hash[state[l]])
				{
					hash[state[l]]=1;
					if(!hash[state[l-1]])
						hash[state[l-1]]=1;
					else 
					{
						state[l-1]=state[l];
						state[l]=0;
						l--;
					}
				}
				else 
				{
					state[l]=0;
					l--;
				    if(!hash[state[l]])
					hash[state[l]]=1;
					else 
					{
						state[l]=0;
						l--;
					}
				}
			}
			else
			{
				if(!hash[state[l]])
					hash[state[l]]=1;
				else 
				{
					state[l]=0;
					l--;
				}
			}
     		l++;		
		}
		n=m=0;
		for(i=0;i<l;i++)
		{
			bool flag=0;
			if(!visit[i]&&!visit1[i])
			{
			for(j=0;j<l;j++)
			{
				if(i!=j)
				{
				if(!visit[j])
				{
					visit[i]=1;
					if(compare(state[i],state[j],N))
					{
						flag=1;
					
						if(!visit1[j])
						{  
					      map[n][m]=1;
						  visit1[j]=1;
						  r[m]=state[j];
						  m++;
						}
						else
						{
							for(int w=0;w<m;w++)
							{
								if(r[w]==state[j])
								{
									map[n][w]=1;
								}
							}
						}
					
					}
				}
				}
			}
			}
			if(flag)
				n++;
		}
        memset(match,-1,sizeof(match));
		for(i=0;i<n;i++)
		{
			memset(visit2,0,sizeof(visit2));
			dfs(i);
		}
		int sum=0;
		for(i=0;i<m;i++)
		{
			if(match[i]!=-1)
			sum++;
		}
		printf("%d\n",l-sum);
	}
	
}
have run 187MS

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