poj 3740 Easy Finding 精确匹配
dlx的第一题, 真是坎坷.....
- #include <iostream>
- #include <vector>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <map>
- #include <set>
- #include <string>
- #include <queue>
- using namespace std;
- #define pb(x) push_back(x)
- #define ll long long
- #define mk(x, y) make_pair(x, y)
- #define lson l, m, rt<<1
- #define mem(a) memset(a, 0, sizeof(a))
- #define rson m+1, r, rt<<1|1
- #define mem1(a) memset(a, -1, sizeof(a))
- #define mem2(a) memset(a, 0x3f, sizeof(a))
- #define rep(i, a, n) for(int i = a; i<n; i++)
- #define ull unsigned long long
- typedef pair<int, int> pll;
- const double PI = acos(-1.0);
- const double eps = 1e-;
- const int mod = 1e9+;
- const int inf = ;
- const int dir[][] = { {-, }, {, }, {, -}, {, } };
- const int maxn = ;
- const int maxNode = ;
- struct DLX {
- int L[maxNode], R[maxNode], U[maxNode], D[maxNode], row[maxNode], col[maxNode];
- int S[maxn], H[maxn], deep, ans[maxn], sz, n, m;
- void remove(int c) {
- L[R[c]] = L[c] ;
- R[L[c]] = R[c] ;
- for(int i = D[c]; i!=c; i = D[i])
- for(int j = R[i]; j!=i; j = R[j]) {
- U[D[j]] = U[j] ;
- D[U[j]] = D[j] ;
- S[col[j]]--;
- }
- }
- void resume(int c) {
- for(int i = U[c]; i!=c; i = U[i])
- for(int j = L[i]; j!=i; j = L[j]) {
- S[col[j]]++;
- D[U[j]] = j;
- U[D[j]] = j;
- }
- R[L[c]] = c;
- L[R[c]] = c;
- }
- int dfs(int d) {
- if(R[] == ) {
- deep = d;
- return ;
- }
- int c = R[];
- for(int i = R[]; i!=; i = R[i])
- if(S[c]>S[i])
- c = i;
- remove(c);
- for(int i = D[c]; i!=c; i = D[i]) {
- ans[d] = row[i];
- for(int j = R[i]; j!=i; j = R[j])
- remove(col[j]);
- if(dfs(d+))
- return ;
- for(int j = L[i]; j!=i; j = L[j])
- resume(col[j]);
- }
- resume(c);
- return ;
- }
- void add(int r, int c) {
- sz++;
- row[sz] = r;
- col[sz] = c;
- S[c]++;
- U[sz] = U[c];
- D[sz] = c;
- D[U[c]] = sz;
- U[c] = sz;
- if(~H[r]) {
- R[sz] = H[r];
- L[sz] = L[H[r]];
- L[R[sz]] = sz;
- R[L[sz]] = sz;
- } else {
- H[r] = L[sz] = R[sz] = sz;
- }
- }
- void init(){
- mem1(H);
- for(int i = ; i<=n; i++) {
- R[i] = i+;
- L[i] = i-;
- U[i] = i;
- D[i] = i;
- }
- R[n] = ;
- L[] = n;
- sz = n;
- }
- void solve () {
- init() ;
- for(int i = ; i<=m; i++) {
- for(int j = ; j<=n; j++) {
- int x;
- scanf("%d", &x);
- if(x) {
- add(i, j);
- }
- }
- }
- if(dfs()) {
- printf("Yes, I found it\n");
- } else {
- printf("It is impossible\n");
- }
- }
- }dlx;
- int main()
- {
- while(~scanf("%d%d", &dlx.m, &dlx.n)) {
- dlx.solve();
- }
- return ;
- }
poj 3740 Easy Finding 精确匹配的更多相关文章
- poj 3740 Easy Finding(Dancing Links)
Easy Finding Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15668 Accepted: 4163 Des ...
- [ACM] POJ 3740 Easy Finding (DLX模板题)
Easy Finding Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16178 Accepted: 4343 Des ...
- poj 3740 Easy Finding 二进制压缩枚举dfs 与 DLX模板详细解析
题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 ...
- [ACM] POJ 3740 Easy Finding (DFS)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16202 Accepted: 4349 Description Give ...
- POJ 3740 Easy Finding
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- POJ_3740 Easy Finding ——精确覆盖问题,DLX模版
Easy Finding Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18790 Accepted: 5184 Des ...
- Easy Finding POJ - 3740 (DLX)
显然这是一道dfs简单题 或许匹配也能做 然而用了dancing links 显然这也是一道模板题 好的吧 调了一上午 终于弄好了模板 Easy Finding Time Limit: 1000MS ...
- 三思考,实现自己定义404页:Tomcat、SpringMVC精确匹配、重写DispatchServlet
第1种方式:Tomcat直接处理 web.xml <error-page> <error-code>404</error-code> <location> ...
- awk使用正则精确匹配
[root@localhost home]# cat file 5001][YRSD5-1][YRSD5-1-2][0203008400028411] 010102 5001][YRSD7-1][YR ...
随机推荐
- zen-Coding的使用
zen-Coding的使用 zen-Coding的使用需要掌握CSS和HTML相关知识.其实只要对CSS的选择器比较熟悉,就可以得用简短的类似于CSS选择器的代码高效的编写出HTML代码.打开Note ...
- iOS百度推送的基本使用
一.iOS证书指导 在 iOS App 中加入消息推送功能时,必须要在 Apple 的开发者中心网站上申请推送证书,每一个 App 需要申请两个证书,一个在开发测试环境下使用,另一个用于上线到 App ...
- iOS调用系统声音与振动
如何调用系统声音?[iphone 调用系统铃声与震动功能] 首先要在工程里加入Audio Toolbox framework这个库,然后在需要调用的文件里#import <AudioToolbo ...
- fs读取某个json文件的数据
/** * Created by Administrator on 2016/7/12. * 流数据 */ var fs = require('fs'); var stream = fs.create ...
- PHP性能如何实现全面优化?
性能是网站运行是否良好的关键因素, 网站的性能与效率影响着公司的运营成本及长远发展,编写出高质高效的代码是我们每个开发人员必备的素质,也是我们良好的职业素养. 如何优化PHP性能呢? 一.变量(重要) ...
- BZOJ 1087 互不侵犯king
Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. Input 只有一行,包 ...
- nginx 几个参数
worker_processes : When set to 'auto', which is also the default behavior, Tengine will create the s ...
- C++小知识之Vector排序
// sort algorithm example #include <iostream> // std::cout #include <algorithm> / ...
- 不能取组织ID
应用 Oracle Purchasing 层 Level Function 函数名 Funcgtion Name PO_POXBWVRP 表单名 Form Name POXBWVRP 说明 Des ...
- C函数数组元素初始化
初始化时,可随意指定初始化的元素或者元素的范围. 附gnu c 手册. http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html 代码: t ...