`
digiter
  • 浏览: 118411 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

DLX hust 1017

    博客分类:
  • ICPC
阅读更多
“精确覆盖”问题
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define out(v) cout << #v << ": " << (v) << endl
using namespace std;
typedef long long LL;

const int max_size = 1005 * 105;
const int maxint = 0x3f3f3f3f;
int L[max_size], R[max_size], U[max_size], D[max_size], CH[max_size], RH[max_size];
int S[1005], O[1005];
int head, size;

void remove(const int &c) {
	//remove column c and all row i that A[i][c] == 1
	L[R[c]] = L[c];
	R[L[c]] = R[c];
	//remove column c;
	for (int i = D[c]; i != c; i = D[i]) {
	//remove i that A[i][c] == 1
		for (int j = R[i]; j != i; j = R[j]) {
			U[D[j]] = U[j];
			D[U[j]] = D[j];
			--S[CH[j]];
			//decrease the count of column C[j];
		}
	}
}
void resume(const int &c) {
	for (int i = U[c]; i != c; i = U[i]) {
		for (int j = L[i]; j != i; j = L[j]) {
			++S[CH[j]];
			U[D[j]] = j;
			D[U[j]] = j;
		}
	}
	L[R[c]] = c;
	R[L[c]] = c;
}
int len;
bool dfs(const int &k) {
	//cout << "new DFS" << endl;
	if (R[head] == head) {
		//One of the answers has been found.
		return true;
	}
	int s(maxint), c;
	//out(head);
	for (int t = R[head]; t != head; t = R[t]) {
		//out(t); out(R[t]);
		//select the column c which has the fewest number of element.
		if (S[t] < s) {
			s = S[t];
			c = t;
		}
	}
	//cout << "remove " << c << endl;
	remove(c);
	for (int i = D[c]; i != c; i = D[i]) {
		O[k] = i; //record the answer.
		len = k;
		for (int j = R[i]; j != i; j = R[j]) {
			remove(CH[j]);
		}
		if (dfs(k + 1)) {
			return true;
		}
		for (int j = L[i]; j != i; j = L[j]) {
			resume(CH[j]);
		}
	}
	resume(c);
	return false;
}
int node(int up, int down, int left, int right) {
	U[size] = up, D[size] = down;
	L[size] = left, R[size] = right;
	D[up] = U[down] = R[left] = L[right] = size;
	return size++;
}
void init(int M) {
	size = 0;
	head = node(0, 0, 0, 0);
	for (int j = 1; j <= M; ++j) {
		node(j, j, L[head], head);
		CH[j] = j, S[j] = 0;
	}
}

int main()
{
	int N, M, cnt;
	while (scanf("%d%d", &N, &M) != EOF)
	{
		init(M);
		for (int i = 1; i <= N; ++i) {
			scanf("%d", &cnt);
			int row = -1;
			while (cnt--) {
				int j;
				scanf("%d", &j);
				CH[size] = j, ++S[j];
				if (row == -1) {
					row = node(U[CH[j]], CH[j], size, size);
					RH[row] = i;
				} else {
					int k = node(U[CH[j]], CH[j], L[row], row);
					RH[k] = i;
				}
			}
		}
		//out("DFS");
		bool ans = dfs(1);
		if (ans) {
			printf("%d", len);
			for (int i = 1; i <= len; ++i)
				printf(" %d", RH[O[i]]);
			printf("\n");
		} else {
			printf("NO\n");
		}
	}
	return 0;
}
分享到:
评论

相关推荐

    dlx指令 DLX Instruction Set Architecture

    DLX Instruction Set Architecture

    DLX汇编器模拟器

    一款很好用的DLX汇编器,链接器,模拟dlx环境,win7下可视

    mips-dlx模拟器

    这是一个用java写得dlx模拟器,实现了流水线和解决相关

    dlx.zip_DLX_cpu dlx_dlx c++_vhdl_vhdl dlx

    DLX CPU VHDL CODE UNIVERSITY

    计算机体系结构dlx实验报告

    学习使用 DLX 汇编语言编程,进一步分析相关现象。 二、实验设备环境 DLX 汇编语言环境 三、实验内容和要求 自编一段汇编代码,完成一维向量加法运算,并输出结果。观察程序中出现的数据/控 制/结构相关。(注:使用...

    dlx语言写的求和

    dlx语言写的求和运算,计算机系统结构试验

    LordPE DLX增强豪华版

    LordPE DLX增强豪华版 (1) 为LordPE查看输入表部分加上搜索功能 (2) 为LordPE查看输入表部分加右键菜单(仅复制ThunkRVA/FirstThunk列). (3) 当点击LordPE查看输入表部分中"View always FirstThunk",保持光条在原来...

    DLX.rar_DLX_dlx文件

    DLX指令集实现程序,将汇编代码转换成二进制代码写入文件中。

    DLX.zip_DLX_dlx算法

    DLX算法,是由Knuth提出的一种在图论中图遍历的一种高效算法。

    DLX修改器第一版

    用于修改H1、H2步步高学习机内部DLX文件内的图片,从而达到修改学习机内部程序图片显示的效果

    DLX.zip_DLX

    DLX用于高效率搜索,是一种覆盖问题模型的算法。DLX利用了双向链表,体现了数据结构的美。

    DLX实验报告

    DLX流水线指令调度,测试指令调度对系统性能的影响。包括实验过程,截图,实验原理和改进方法等,供同学们参考。蔡老师的学生你们懂的。

    比较好用的DLX模拟器

    大作业写的MIPS DLX的模拟器 应该是比较好用的。。

    LordPE DLX增强版

    (1) 为LordPE查看输入表部分加上搜索功能 (2) 为LordPE查看输入表部分加右键菜单(复制ThunkRVA/FirstThunk列). (3) 当点击LordPE查看输入表部分中"View always FirstThunk",保持光条在原来位置.(LordPE默认会将光条...

    windlx模拟器 and DLX实验指导书.pdf

    windlx模拟器 DLX实验指导书windlx模拟器 DLX实验指导书

    DLX处理器浮点数流水线性能的研究.pdf

    DLX处理器浮点数流水线性能的研究.pdf关于DLX的参考文献

    dlx.tar.gz_DLX

    A VHDL implementation DLX processor

    DLX指令集(BYU版本)

    这些指令既没有出现在Hennessy 和 Patterson的课本中,也没有列在Sailer 和 Kaeli 合编的"The DLX Instruction Set Architecture Handbook"一书中。新的指令是:sgeu, sgtu, sleu, sltu -- all compares using ...

    DLX.zip_DLX_体系仿真_开发DLX

    DLX实现,实用Visual C++编程,思想为MIPS体系结构,可以考察系统仿真的性能和指标

    LPE-DLX 经典

    懂得不用多介绍了把,下载享用吧

Global site tag (gtag.js) - Google Analytics