标签:lap 目标 space style sof scanf family 大小 ros
对于100%的数据,N≤ 200
solution
二分图
如果a[i][j]==1,就把i行向j列连一条边,最后跑二分图
(我还打了爆搜......)
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #define mem(a,b) memset(a,b,sizeof(a)) 5 using namespace std; 6 7 struct son 8 { 9 int v,next; 10 }; 11 son a1[100006]; 12 int first[100006],e; 13 void addbian(int u,int v) 14 { 15 a1[e].v=v; 16 a1[e].next=first[u]; 17 first[u]=e++; 18 } 19 20 int T,n; 21 int a[206][206]; 22 bool vis[206]; 23 int match[206]; 24 25 bool fin(int x) 26 { 27 for(int i=first[x];i!=-1;i=a1[i].next) 28 { 29 int temp=a1[i].v; 30 if(!vis[temp]) 31 { 32 vis[temp]=1; 33 if(match[temp]==-1||fin(match[temp])) 34 { 35 match[temp]=x; 36 return 1; 37 } 38 } 39 } 40 return 0; 41 } 42 43 int main(){ 44 45 //freopen("qmatrix.in","r",stdin); 46 //freopen("qmatrix.out","w",stdout); 47 48 scanf("%d",&T); 49 while(T--) 50 { 51 mem(match,-1); 52 mem(a1,0);mem(first,-1);e=0; 53 scanf("%d",&n); 54 for(int i=1;i<=n;++i) 55 for(int j=1;j<=n;++j) 56 scanf("%d",&a[i][j]); 57 58 for(int i=1;i<=n;++i) 59 for(int j=1;j<=n;++j) 60 if(a[i][j]) 61 { 62 addbian(i,j); 63 } 64 65 int num=0; 66 for(int i=1;i<=n;++i) 67 { 68 mem(vis,0); 69 if(fin(i)) 70 ++num; 71 } 72 73 if(num==n) 74 printf("Yes\n"); 75 else 76 printf("No\n"); 77 } 78 //while(1); 79 return 0; 80 } 81
标签:lap 目标 space style sof scanf family 大小 ros
原文地址:http://www.cnblogs.com/A-LEAF/p/7348652.html