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 PwnMe解题思路
阿里聚安全攻防挑战赛第三题Android PwnMe解题思路 大家在聚安全挑战赛正式赛第三题中,遇到android app 远程控制的题目.我们今天带你一探究竟,如何攻破这道题目. 一.题目 购物应用 ...
- Linux 调节屏幕亮度
intel的核心显卡驱动是在 /sys/class/backlight/intel_backlight/ 目录下面的brightness文件中配置的. 可以通过查看max_brightness的值来确 ...
- Log设计
Log设计 http://biancheng.dnbcw.info/net/380312.html http://blog.csdn.net/anyqu/article/details/7937378 ...
- AP(应付帐管理)
--更新供应商地点 PROCEDURE update_vendor_site(p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false, x_return ...
- 对于C语言中数组名是指针的理解
我们都知道,c语言中数组名是一个指针,比如下面这段代码 #include<iostream>using namespace std;int main(){ int a[4]={1,2,3, ...
- win7和linux下的文件共享
在vmware虚拟机下安装linux系统,如果自个电脑的win7设置成自动获取IP的话,每次使用FTP文件传输服务器都要检查win7和linux系统的IP是否处于同一网段,如果不是还要手动设置.再有一 ...
- XHTML标签的嵌套规则--很基础很重要
XHTML的标签有许多:div.ul.li.dl.dt.dd.h1~h6.p.a.addressa.span. strong……我们在运用这些标签搭建页面结构的时候,是可以将它们无限嵌套的,但是,嵌套 ...
- MySQL 错误代码和消息
本章列出了当你用任何主机语言调用MySQL时可能出现的错误.首先列出了服务器错误消息.其次列出了客户端程序消息. B.1. 服务器错误代码和消息 服务器错误信息来自下述源文件: · 错 ...
- UVALive 4225 Prime Bases 贪心
Prime Bases 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&a ...
- UITableViewCell重用机制
UITableView是iOS开发中使用频率非常高的一个控件,它常被用来展示信息列表,尽管信息数据可能非常多,但UITableView消耗的资源却并不会随着展示信息的增多而变大,这都要得益于UITab ...