hust 1017 DLX
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define Maxn 1000010
#define Maxm 80002
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 100000
#define lowbit(x) (x&(-x))
#define Mod 1000000007
using namespace std;
int U[Maxn],D[Maxn],R[Maxn],L[Maxn],C[Maxn],S[Maxn],X[Maxn],H[],Q[],id;
void init(int m)
{
int i;
for(i=;i<=m;i++){
D[i]=U[i]=i;
L[i+]=i;
R[i]=i+;
S[i]=;
}
R[m]=;
id=m+;
}
void ins(int r,int c)
{
D[id]=D[c];
U[id]=c;
U[D[c]]=id;
D[c]=id;
S[c]++;
if(H[r]<)
H[r]=L[id]=R[id]=id;
else{
L[id]=H[r];
R[id]=R[H[r]];
L[R[H[r]]]=id;
R[H[r]]=id;
}
C[id]=c;
X[id++]=r;
}
void Remove(int c)
{
int i,j;
R[L[c]]=R[c];
L[R[c]]=L[c];
for(i=D[c];i!=c;i=D[i]){
for(j=R[i];j!=i;j=R[j]){
D[U[j]]=D[j];
U[D[j]]=U[j];
S[C[j]]--;
}
}
}
void Resume(int c)
{
int i,j;
R[L[c]]=c;
L[R[c]]=c;
for(i=D[c];i!=c;i=D[i]){
for(j=R[i];j!=i;j=R[j]){
U[D[j]]=j;
D[U[j]]=j;
S[C[j]]++;
}
}
}
bool dfs(int k)
{
int i,j,c,temp;
if(R[]==){
printf("%d",k);
for(i=;i<k;i++){
printf(" %d",X[Q[i]]);
}
printf("\n");
return true;
}
temp=inf;
for(i=R[];i;i=R[i]){
if(S[i]<temp){
temp=S[i];
c=i;
}
}
Remove(c);
for(i=D[c];i!=c;i=D[i]){
Q[k]=i;
for(j=R[i];j!=i;j=R[j])
Remove(C[j]);
if(dfs(k+))
return true;
for(j=L[i];j!=i;j=L[j])
Resume(C[j]);
} Resume(c);
return false;
}
int main()
{
int n,m,i,j,k,x;
while(scanf("%d%d",&n,&m)!=EOF){
init(m);
for(i=;i<=n;i++){
scanf("%d",&k);
H[i]=-;
while(k--){
scanf("%d",&x);
ins(i,x);
}
}
if(!dfs())
printf("NO\n");
}
return ;
}
思路:裸的精确覆盖
hust 1017 DLX的更多相关文章
- [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 ...
- (简单) 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 ...
- HUST 1017(DLX)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65998#problem/A 题意:求01矩阵的精确覆盖. DLX学习资料:ht ...
- 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 ...
- [DLX] hust 1017 Exact cover
题意: 给你N个包,要拿到M个东西(编号1~M每一个仅仅能有一个) 然后每一个包里有k个东西,每一个东西都有编号. 思路: 舞蹈连模板题 代码: #include"stdio.h" ...
- HUST 1017 - Exact cover (Dancing Links 模板题)
1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...
- Dancing Link --- 模板题 HUST 1017 - Exact cover
1017 - Exact cover Problem's Link: http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...
- HUST 1017 Exact cover (Dancing links)
1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 6110 次提交 3226 次通过 题目描述 There is an N*M matrix with only 0 ...
- [HUST 1017] Exact cover
Exact cover Time Limit: 15s Memory Limit: 128MB Special Judge Submissions: 6012 Solved: 3185 DESCRIP ...
随机推荐
- Cipher Message
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=34121#problem/C // File Name: c.cpp // Author: ...
- 【转】C++ 异常
一.什么是异常处理 一句话:异常处理就是处理程序中的错误. 二.为什么需要异常处理,以及异常处理的基本思想 C++之父Bjarne Stroustrup在<The C++ Programming ...
- 【React Native 实战】商品分类
1.前言 商品分类是各种app常见的一种操作,一般都是左右两栏构成,左边栏是商品的分类,右边栏是商品的展示,同时左右两栏都可以滑动.今天我们就用React Native来实现这种效果. 实现内容:1) ...
- 《MySQL必知必会》读书笔记
一.了解MySQL 1.什么是数据库? 数据库是一种以某种有组织的方式存储的数据集合. 2.模式(schema):关于数据库和表的布局及特性的信息. 3. ...
- iOS开发——UI篇Swift篇&UIImageView
UIImageView override func viewDidLoad() { super.viewDidLoad() titleLabel.text = titleString //通过坐标和大 ...
- JavaWeb学习总结
http://www.cnblogs.com/xdp-gacl/tag/JavaWeb%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/ http://www.cnblogs. ...
- java中无符号类型的处理
在Java中,不存在Unsigned无符号数据类型,但可以轻而易举的完成Unsigned转换. 方案一:如果在Java中进行流(Stream)数据处理,可以用DataInputStream类对Stre ...
- Python高级编程–正则表达式(习题)
原文:http://start2join.me/python-regex-answer-20141030/ ############################################## ...
- 小白日记49:kali渗透测试之Web渗透-XSS(三)-存储型XSS、DOM型XSS、神器BEFF
存储型XSS与DOM型XSS [XSS原理] 存储型XSS 1.可长期存储于服务器端 2.每次用户访问都会被执行js脚本,攻击者只需侦听指定端口 #攻击利用方法大体等于反射型xss利用 ##多出现在留 ...
- BootStrap2学习日记14----导航
<div class="navbar navbar-inverse navbar-fixed-top"> <div class="navbar-inne ...