//题意:类比线代里:把矩阵中的U看作【1】,是否满足一个满秩矩阵

//利用二分匹配就是

//每一行都有相对应的列;

  1. #include<iostream>
  2. #include<string.h>
  3. #include<set>
  4. #include<queue>
  5. #include<sstream>
  6. using namespace std;
  7. #define N 220
  8. char s[N][N];
  9. int ma[N][N];
  10. bool vis[N];
  11. int cx[N];
  12. int cy[N];
  13. int n;
  14. int findpath(int u)
  15. {
  16. for(int i=0;i<n;i++)
  17. {
  18. if(!vis[i]&&ma[u][i])
  19. {
  20. vis[i]=1;
  21. if(cy[i]==-1||findpath(cy[i]))
  22. {
  23. cy[i]=u;
  24. cx[u]=i;
  25. return 1;
  26. }
  27. }
  28. }
  29. return 0;
  30. }
  31. int main()
  32. {
  33. while(~scanf("%d",&n))
  34. {
  35. memset(ma,0,sizeof(ma));
  36. for(int i=0;i<n;i++)
  37. {
  38. scanf("%s",s[i]);
  39. for(int j=0;j<n;j++)
  40. {
  41. if(s[i][j]=='U')
  42. ma[i][j]=1;
  43. }
  44. }
  45. int ans=0;
  46. memset(cx,-1,sizeof(cx));
  47. memset(cy,-1,sizeof(cy));
  48. for(int i=0;i<n;i++)
  49. {
  50. if(cx[i]==-1)
  51. {
  52. memset(vis,0,sizeof(vis));
  53. ans+=findpath(i);
  54. }
  55. }
  56. if(ans==n)
  57. {
  58. printf("YES\n");
  59. }
  60. else
  61. printf("NO\n");
  62. }
  63. return 0;
  64. }

二分匹配ZOJ3646的更多相关文章

  1. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  2. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  3. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  4. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  5. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  6. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  7. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  8. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

  9. UVA5874 Social Holidaying 二分匹配

    二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...

随机推荐

  1. 紫书p199 八数码(BFS,hash)

    八数码问题  紫书上的简单搜索  渣渣好久才弄懂 #include<cstdio> #include<cstring> using namespace std; const i ...

  2. STL algorithm算法max,max_elements(33)

    max原型: std::max C++98 C++11 C++14 default (1) template <class T> const T& max (const T& ...

  3. Androidclient验证Licence的原理

    需求 限制App的使用,使App仅仅能在有许可的设备上执行. 分析及解决方式 原理 让App在每次执行的时候都连接server进行合法性验证--当然是一个非常成熟可靠的方案. 可是这样做的局限也是每次 ...

  4. OpenStack Live Migration

    About live migration of KVM virtual machines with NFS storage, from Mirantis blog: click this link w ...

  5. HDU 1022 Train Problem I (数据结构 —— 栈)

    Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...

  6. FZUOJ Problem 2200 cleaning DP

    Problem 2200 cleaning  Problem Description N个人围成一圈在讨论大扫除的事情,需要选出K个人.但是每个人与他距离为2的人存在矛盾,所以这K个人中任意两个人的距 ...

  7. sim的准确识别技术

    几个月钱,我换了一个手机,本着工科男动手能力强的原则,自己用✂️把sim卡剪成了一个小卡,然后成功的可以使用了. 然而就在昨天,我将卡拿出之后,再放回去,却无法识别我的sim卡了. 我上网查了方法,怀 ...

  8. R学习-- 数组和矩阵

    生成 4行5列的数组,逐列逐行赋值x = array(1:20, dim= c(4,5)) 依据已知向量生成二维数组i = array(c(1:3,3:1,4:6,5:7), dim=c(3,4))也 ...

  9. RSA前端JS加密,后端JAVA解密实现

    用RSA非对称加密方式实现.后台生成rsa密钥对,然后在页面设置rsa公钥,提交时用公钥加密密码,生成的密文传到后台,后台再用私钥解密,获取密码明文.这样客户端只需要知道rsa加密方式和公钥,前台不知 ...

  10. IOS中UIActionSheet使用方法详解

    一.初始化方法 - (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)de ...