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

-_- 为什么动态开辟数组 RE -_-

Posted by dreamseeker at 2007-01-16 14:34:13 on Problem 1469
#include"iostream"
using namespace std;
bool **g;
int n,m;
int *mat;
int *tmat;
int find(int i)
{
	int v,j;
	for (j=0;j<m;j++)
		if (g[i][j]&&tmat[j]==0)
		{
			tmat[j]=1;v=mat[j];
			mat[j]=i;
			if (v==-1||find(v)) return 1;
			mat[j]=v;
		}
		return 0;
}
int match()
{
	int i,j,k=0;
	for(i=0;i<n;i++)
		mat[i]=-1;
	for (i=0;i<n;i++)
	{
        for (j=0;j<m;j++)
			tmat[j]=0;
		k+=find(i);
	}
	return k;
}
int main()
{
	int i,j,t,p,Case;
	scanf("%d",&Case);
	while(Case--)
	{
		scanf("%d %d",&n,&m);
		g=new bool *[n];
		for (i=0;i<n;i++)
			g[i]= new bool [m];
		mat= new int [n];
		tmat= new int [m];
		for (i=0;i<n;i++)
			for (j=0;j<m;j++)
				g[i][j]=false;
			for (i=0;i<n;i++)
			{
				scanf("%d",&t);
				while(t--)
				{
					scanf("%d",&p);
					g[i][p-1]=true;
				}
			}  
			if(match()==n)
				printf("YES\n");
			else
				printf("NO\n");
			delete []mat;
			delete []tmat;
			for (i=0;i<n;i++)
				delete[]g[i];
			delete []g;
		}	
		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