1. #include<set>
  2. #include<cmath>
  3. #include<queue>
  4. #include<cstdio>
  5. #include<vector>
  6. #include<string>
  7. #include<cstdlib>
  8. #include<cstring>
  9. #include<iostream>
  10. #include<algorithm>
  11. #define pb push_back
  12. #define mp make_pair
  13. #define Maxn 1000010
  14. #define Maxm 80002
  15. #define LL __int64
  16. #define Abs(x) ((x)>0?(x):(-x))
  17. #define lson(x) (x<<1)
  18. #define rson(x) (x<<1|1)
  19. #define inf 100000
  20. #define lowbit(x) (x&(-x))
  21. #define Mod 1000000007
  22. using namespace std;
  23. int U[Maxn],D[Maxn],R[Maxn],L[Maxn],C[Maxn],S[Maxn],X[Maxn],H[],Q[],id;
  24. void init(int m)
  25. {
  26. int i;
  27. for(i=;i<=m;i++){
  28. D[i]=U[i]=i;
  29. L[i+]=i;
  30. R[i]=i+;
  31. S[i]=;
  32. }
  33. R[m]=;
  34. id=m+;
  35. }
  36. void ins(int r,int c)
  37. {
  38. D[id]=D[c];
  39. U[id]=c;
  40. U[D[c]]=id;
  41. D[c]=id;
  42. S[c]++;
  43. if(H[r]<)
  44. H[r]=L[id]=R[id]=id;
  45. else{
  46. L[id]=H[r];
  47. R[id]=R[H[r]];
  48. L[R[H[r]]]=id;
  49. R[H[r]]=id;
  50. }
  51. C[id]=c;
  52. X[id++]=r;
  53. }
  54. void Remove(int c)
  55. {
  56. int i,j;
  57. R[L[c]]=R[c];
  58. L[R[c]]=L[c];
  59. for(i=D[c];i!=c;i=D[i]){
  60. for(j=R[i];j!=i;j=R[j]){
  61. D[U[j]]=D[j];
  62. U[D[j]]=U[j];
  63. S[C[j]]--;
  64. }
  65. }
  66. }
  67. void Resume(int c)
  68. {
  69. int i,j;
  70. R[L[c]]=c;
  71. L[R[c]]=c;
  72. for(i=D[c];i!=c;i=D[i]){
  73. for(j=R[i];j!=i;j=R[j]){
  74. U[D[j]]=j;
  75. D[U[j]]=j;
  76. S[C[j]]++;
  77. }
  78. }
  79. }
  80. bool dfs(int k)
  81. {
  82. int i,j,c,temp;
  83. if(R[]==){
  84. printf("%d",k);
  85. for(i=;i<k;i++){
  86. printf(" %d",X[Q[i]]);
  87. }
  88. printf("\n");
  89. return true;
  90. }
  91. temp=inf;
  92. for(i=R[];i;i=R[i]){
  93. if(S[i]<temp){
  94. temp=S[i];
  95. c=i;
  96. }
  97. }
  98. Remove(c);
  99. for(i=D[c];i!=c;i=D[i]){
  100. Q[k]=i;
  101. for(j=R[i];j!=i;j=R[j])
  102. Remove(C[j]);
  103. if(dfs(k+))
  104. return true;
  105. for(j=L[i];j!=i;j=L[j])
  106. Resume(C[j]);
  107. }
  108.  
  109. Resume(c);
  110. return false;
  111. }
  112. int main()
  113. {
  114. int n,m,i,j,k,x;
  115. while(scanf("%d%d",&n,&m)!=EOF){
  116. init(m);
  117. for(i=;i<=n;i++){
  118. scanf("%d",&k);
  119. H[i]=-;
  120. while(k--){
  121. scanf("%d",&x);
  122. ins(i,x);
  123. }
  124. }
  125. if(!dfs())
  126. printf("NO\n");
  127. }
  128. return ;
  129. }

思路:裸的精确覆盖

hust 1017 DLX的更多相关文章

  1. [ACM] HUST 1017 Exact cover (Dancing Links,DLX模板题)

    DESCRIPTION There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is ...

  2. (简单) HUST 1017 Exact cover , DLX+精确覆盖。

    Description There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is ...

  3. HUST 1017(DLX)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65998#problem/A 题意:求01矩阵的精确覆盖. DLX学习资料:ht ...

  4. HUST 1017 Exact cover(DLX精确覆盖)

    Description There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is ...

  5. [DLX] hust 1017 Exact cover

    题意: 给你N个包,要拿到M个东西(编号1~M每一个仅仅能有一个) 然后每一个包里有k个东西,每一个东西都有编号. 思路: 舞蹈连模板题 代码: #include"stdio.h" ...

  6. HUST 1017 - Exact cover (Dancing Links 模板题)

    1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...

  7. Dancing Link --- 模板题 HUST 1017 - Exact cover

    1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...

  8. HUST 1017 Exact cover (Dancing links)

    1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 6110 次提交 3226 次通过 题目描述 There is an N*M matrix with only 0 ...

  9. [HUST 1017] Exact cover

    Exact cover Time Limit: 15s Memory Limit: 128MB Special Judge Submissions: 6012 Solved: 3185 DESCRIP ...

随机推荐

  1. 阿里聚安全攻防挑战赛第三题Android PwnMe解题思路

    阿里聚安全攻防挑战赛第三题Android PwnMe解题思路 大家在聚安全挑战赛正式赛第三题中,遇到android app 远程控制的题目.我们今天带你一探究竟,如何攻破这道题目. 一.题目 购物应用 ...

  2. Linux 调节屏幕亮度

    intel的核心显卡驱动是在 /sys/class/backlight/intel_backlight/ 目录下面的brightness文件中配置的. 可以通过查看max_brightness的值来确 ...

  3. Log设计

    Log设计 http://biancheng.dnbcw.info/net/380312.html http://blog.csdn.net/anyqu/article/details/7937378 ...

  4. AP(应付帐管理)

    --更新供应商地点 PROCEDURE update_vendor_site(p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false, x_return ...

  5. 对于C语言中数组名是指针的理解

    我们都知道,c语言中数组名是一个指针,比如下面这段代码 #include<iostream>using namespace std;int main(){ int a[4]={1,2,3, ...

  6. win7和linux下的文件共享

    在vmware虚拟机下安装linux系统,如果自个电脑的win7设置成自动获取IP的话,每次使用FTP文件传输服务器都要检查win7和linux系统的IP是否处于同一网段,如果不是还要手动设置.再有一 ...

  7. XHTML标签的嵌套规则--很基础很重要

    XHTML的标签有许多:div.ul.li.dl.dt.dd.h1~h6.p.a.addressa.span. strong……我们在运用这些标签搭建页面结构的时候,是可以将它们无限嵌套的,但是,嵌套 ...

  8. MySQL 错误代码和消息

    本章列出了当你用任何主机语言调用MySQL时可能出现的错误.首先列出了服务器错误消息.其次列出了客户端程序消息. B.1. 服务器错误代码和消息 服务器错误信息来自下述源文件: ·         错 ...

  9. UVALive 4225 Prime Bases 贪心

    Prime Bases 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&a ...

  10. UITableViewCell重用机制

    UITableView是iOS开发中使用频率非常高的一个控件,它常被用来展示信息列表,尽管信息数据可能非常多,但UITableView消耗的资源却并不会随着展示信息的增多而变大,这都要得益于UITab ...