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 ...
随机推荐
- android 动画NineOldAndroid
NineOldAndroid 1.之前我们用到的第动画是frame和tween动画也就是帧动画,补间动画现在多了一种动画,它包含完了前面动画的所有状态. 属性动画(Property Anmation) ...
- android 小知识点
小知识点总结 1. android中MotionEvent.ACTION_CANCEL事件如何被触发? 对于这个问题,android文档的说明很简短,想看明白很难.国外一网页说的还比较详细,写在这里分 ...
- android 动画属性(一)之Animation
Animation 在android 程序当中很多时候要用到动画效果,而动画效果主要是Animation来实现的,API给出的解释: 其中包含4种动画效果 AlphaAnimation 渐变透明度 R ...
- ASP.NET服务器控件在IE10浏览器(非兼容模式)下报脚本错误的可能解决办法
关于IE10出现LinkButton点击无效的情况: 一般高配置的系统如Win7旗舰版SP1系统不会出现这种情况,针对家庭普通版和专业版的用户通过测试都有这种情况,对于开发人员要解决不同 ...
- SQLServer: 无法修改表
工具—选项—Designers—表设计器和数据库设计器—阻止保存要求重新创建表的更改前的勾去掉.
- C++ assert()断言
assert是一个宏定义,原型定义在<assert.h>中: #include <assert.h> void assert( int expression ); 其作用是:如 ...
- Microchip 125 kHz RFID System Design Guide
Passive RFID Basics - AN680 INTRODUCTION Radio Frequency Identification (RFID) systems use radio fre ...
- COM组件入门(一)
近期须要用到COM组件的知识,看了看COM编程指南,感觉还不错.把我的学习心得记录下来.这是我依据教程写的demo StopWatch接口实现部分,接口部分我的项目是动态库,主要源代码例如以下: 完整 ...
- CDOJ 第七届ACM趣味程序设计竞赛第三场(正式赛) 题解
宝贵资源 题目连接: http://acm.uestc.edu.cn/#/problem/show/1265 题意 平面上给n个点(n<=1000),要求找一个面积最小的正方形,将所有的点都囊括 ...
- [Express] Level 3: Reading from the URL
City Search We want to create an endpoint that we can use to filter cities. Follow the tasks below t ...