Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
-_- 为什么动态开辟数组 RE -_-#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator