题目链接

dlx的第一题, 真是坎坷.....

  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <map>
  8. #include <set>
  9. #include <string>
  10. #include <queue>
  11. using namespace std;
  12. #define pb(x) push_back(x)
  13. #define ll long long
  14. #define mk(x, y) make_pair(x, y)
  15. #define lson l, m, rt<<1
  16. #define mem(a) memset(a, 0, sizeof(a))
  17. #define rson m+1, r, rt<<1|1
  18. #define mem1(a) memset(a, -1, sizeof(a))
  19. #define mem2(a) memset(a, 0x3f, sizeof(a))
  20. #define rep(i, a, n) for(int i = a; i<n; i++)
  21. #define ull unsigned long long
  22. typedef pair<int, int> pll;
  23. const double PI = acos(-1.0);
  24. const double eps = 1e-;
  25. const int mod = 1e9+;
  26. const int inf = ;
  27. const int dir[][] = { {-, }, {, }, {, -}, {, } };
  28. const int maxn = ;
  29. const int maxNode = ;
  30. struct DLX {
  31. int L[maxNode], R[maxNode], U[maxNode], D[maxNode], row[maxNode], col[maxNode];
  32. int S[maxn], H[maxn], deep, ans[maxn], sz, n, m;
  33. void remove(int c) {
  34. L[R[c]] = L[c] ;
  35. R[L[c]] = R[c] ;
  36. for(int i = D[c]; i!=c; i = D[i])
  37. for(int j = R[i]; j!=i; j = R[j]) {
  38. U[D[j]] = U[j] ;
  39. D[U[j]] = D[j] ;
  40. S[col[j]]--;
  41. }
  42. }
  43. void resume(int c) {
  44. for(int i = U[c]; i!=c; i = U[i])
  45. for(int j = L[i]; j!=i; j = L[j]) {
  46. S[col[j]]++;
  47. D[U[j]] = j;
  48. U[D[j]] = j;
  49. }
  50. R[L[c]] = c;
  51. L[R[c]] = c;
  52. }
  53. int dfs(int d) {
  54. if(R[] == ) {
  55. deep = d;
  56. return ;
  57. }
  58. int c = R[];
  59. for(int i = R[]; i!=; i = R[i])
  60. if(S[c]>S[i])
  61. c = i;
  62. remove(c);
  63. for(int i = D[c]; i!=c; i = D[i]) {
  64. ans[d] = row[i];
  65. for(int j = R[i]; j!=i; j = R[j])
  66. remove(col[j]);
  67. if(dfs(d+))
  68. return ;
  69. for(int j = L[i]; j!=i; j = L[j])
  70. resume(col[j]);
  71. }
  72. resume(c);
  73. return ;
  74. }
  75. void add(int r, int c) {
  76. sz++;
  77. row[sz] = r;
  78. col[sz] = c;
  79. S[c]++;
  80. U[sz] = U[c];
  81. D[sz] = c;
  82. D[U[c]] = sz;
  83. U[c] = sz;
  84. if(~H[r]) {
  85. R[sz] = H[r];
  86. L[sz] = L[H[r]];
  87. L[R[sz]] = sz;
  88. R[L[sz]] = sz;
  89. } else {
  90. H[r] = L[sz] = R[sz] = sz;
  91. }
  92. }
  93. void init(){
  94. mem1(H);
  95. for(int i = ; i<=n; i++) {
  96. R[i] = i+;
  97. L[i] = i-;
  98. U[i] = i;
  99. D[i] = i;
  100. }
  101. R[n] = ;
  102. L[] = n;
  103. sz = n;
  104. }
  105. void solve () {
  106. init() ;
  107. for(int i = ; i<=m; i++) {
  108. for(int j = ; j<=n; j++) {
  109. int x;
  110. scanf("%d", &x);
  111. if(x) {
  112. add(i, j);
  113. }
  114. }
  115. }
  116. if(dfs()) {
  117. printf("Yes, I found it\n");
  118. } else {
  119. printf("It is impossible\n");
  120. }
  121. }
  122. }dlx;
  123. int main()
  124. {
  125. while(~scanf("%d%d", &dlx.m, &dlx.n)) {
  126. dlx.solve();
  127. }
  128. return ;
  129. }

poj 3740 Easy Finding 精确匹配的更多相关文章

  1. poj 3740 Easy Finding(Dancing Links)

    Easy Finding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15668   Accepted: 4163 Des ...

  2. [ACM] POJ 3740 Easy Finding (DLX模板题)

    Easy Finding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16178   Accepted: 4343 Des ...

  3. poj 3740 Easy Finding 二进制压缩枚举dfs 与 DLX模板详细解析

    题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 ...

  4. [ACM] POJ 3740 Easy Finding (DFS)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16202   Accepted: 4349 Description Give ...

  5. POJ 3740 Easy Finding

    #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...

  6. POJ_3740 Easy Finding ——精确覆盖问题,DLX模版

    Easy Finding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18790   Accepted: 5184 Des ...

  7. Easy Finding POJ - 3740 (DLX)

    显然这是一道dfs简单题 或许匹配也能做 然而用了dancing links 显然这也是一道模板题 好的吧 调了一上午 终于弄好了模板 Easy Finding Time Limit: 1000MS ...

  8. 三思考,实现自己定义404页:Tomcat、SpringMVC精确匹配、重写DispatchServlet

    第1种方式:Tomcat直接处理 web.xml <error-page> <error-code>404</error-code> <location> ...

  9. awk使用正则精确匹配

    [root@localhost home]# cat file 5001][YRSD5-1][YRSD5-1-2][0203008400028411] 010102 5001][YRSD7-1][YR ...

随机推荐

  1. zen-Coding的使用

    zen-Coding的使用 zen-Coding的使用需要掌握CSS和HTML相关知识.其实只要对CSS的选择器比较熟悉,就可以得用简短的类似于CSS选择器的代码高效的编写出HTML代码.打开Note ...

  2. iOS百度推送的基本使用

    一.iOS证书指导 在 iOS App 中加入消息推送功能时,必须要在 Apple 的开发者中心网站上申请推送证书,每一个 App 需要申请两个证书,一个在开发测试环境下使用,另一个用于上线到 App ...

  3. iOS调用系统声音与振动

    如何调用系统声音?[iphone 调用系统铃声与震动功能] 首先要在工程里加入Audio Toolbox framework这个库,然后在需要调用的文件里#import <AudioToolbo ...

  4. fs读取某个json文件的数据

    /** * Created by Administrator on 2016/7/12. * 流数据 */ var fs = require('fs'); var stream = fs.create ...

  5. PHP性能如何实现全面优化?

    性能是网站运行是否良好的关键因素, 网站的性能与效率影响着公司的运营成本及长远发展,编写出高质高效的代码是我们每个开发人员必备的素质,也是我们良好的职业素养. 如何优化PHP性能呢? 一.变量(重要) ...

  6. BZOJ 1087 互不侵犯king

    Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. Input 只有一行,包 ...

  7. nginx 几个参数

    worker_processes : When set to 'auto', which is also the default behavior, Tengine will create the s ...

  8. C++小知识之Vector排序

    // sort algorithm example #include <iostream>     // std::cout #include <algorithm>    / ...

  9. 不能取组织ID

    应用 Oracle   Purchasing 层 Level Function 函数名 Funcgtion Name PO_POXBWVRP 表单名 Form Name POXBWVRP 说明 Des ...

  10. C函数数组元素初始化

    初始化时,可随意指定初始化的元素或者元素的范围. 附gnu c 手册. http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html 代码: t ...