bzoj 1059 题解

来源:互联网 发布:新华阅读网软件 编辑:程序博客网 时间:2024/05/16 06:10

二分匹配图,i和j建边

Code:

/**************************************************************    Problem: 1059    User: wohenshuai    Language: C++    Result: Accepted    Time:256 ms    Memory:1316 kb****************************************************************/ #include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;bool map[210][210];bool chw[210];int match[210];int n,t;void Input(){  scanf("%d",&n);  char st; memset(map,0,sizeof(map));  for(int i=1;i<=n;i++)  {    for(int j=1;j<=n;j++)    {      scanf("\n%c",&st);      if(st=='1') map[i][j]=1;    }  }}int ans=0;bool find_cow(int k){  for(int i=1;i<=n;i++)  {    if(map[k][i]&&chw[i])    {      chw[i]=0;      if(match[i]==0||find_cow(match[i]))      {        match[i]=k;        return true;      }    }  }  return false;}void find_ans(){  ans=0;  memset(match,0,sizeof(match));  for(int i=1;i<=n;i++)  {    memset(chw,1,sizeof(chw));    if(find_cow(i)==true) ans++;  }}void Solve(){  find_ans();}void Output(){  if(ans==n) printf("Yes\n");  else printf("No\n");}int main(){  scanf("%d",&t);  while(t--)  {    Input();    Solve();    Output();  }  return 0;}


0 0
原创粉丝点击