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 ...
随机推荐
- TCP应用编程--套接字C#实现
套接字之间的连接过程可以分为三个步骤: 1.服务器监听 2.客户端请求 3.连接确认 Ø服务器监听:是指服务器套接字并不定位具体的客户端套接字,而 是处于等待连接的状态,实时监控网络状态. Ø客户端 ...
- mysql 基本使用
SQL分类 -------------------数据库------------ 创建数据库 create database xxx; 查询所有的数据库 show databases; 查询当前数据 ...
- 第七课 GC资源管理器实验
<GC资源管理器> 要求: 1.定义2个资源消耗组(OLTP事务处理资源消耗组和DSS数据仓库资源消耗组) 2.创建一个日程计划schedule 3.对于OLTP资源消耗组,我们最多不 ...
- 在 PL/SQL Developer 中执行SQL文件的方法
打开 command Window SQL> @'D:\My Documents\Downloads\bde_chk_cbo.sql'; 整个路径及文件两边要有单引号哦!
- FPGA开发(1)
`timescale ns / ns module system_ctrl ( //globol clock input clk, input rst_n, //synced signal outpu ...
- Unity截图
什么都不说了,直接上代码. using UnityEngine; using System.Collections; using System.IO; public class CutImage : ...
- Matlab图像直方图相关函数
图像的灰度直方图(H是图像a.bmp的数据矩阵) imhist(H):%显示a的直方图 histeq(H); %将图像a进行直方图均衡化 adapthisteq(H); %将图像a进行直方图均衡化 i ...
- 关于jQuery中toggle()函数的使用
今天遇到一个有趣的例子,将它记录下来. 一个一级菜单,里边有一个二级菜单,二级菜单是通过锚点来链接页面元素的.想要实现的效果是当点击锚点时,页面链接到相应锚点,同时二级菜单隐藏,再点击一级菜单时,继续 ...
- 精读《javascript高级程序设计》笔记一——基本概念
语法 严格模式 启用严格模式,在脚本顶部或函数内部上方添加"use strict";语句. 数据类型 typeof typeof返回undifined,boolean,number ...
- Android 数据库ORM框架GreenDao学习心得及使用总结<一>
转: http://www.it165.net/pro/html/201401/9026.html 最近在对开发项目的性能进行优化.由于项目里涉及了大量的缓存处理和数据库运用,需要对数据库进行频繁的读 ...