博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HUST 1017 Exact cover
阅读量:7049 次
发布时间:2019-06-28

本文共 2078 字,大约阅读时间需要 6 分钟。

Exact cover

Special Judge
Time Limit: 15 Sec 
Memory Limit: 128 MB
Submissions: 5179 
Solved: 2748

Description

There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in exactly one of the selected rows. Try to find out the selected rows.

Input

There are multiply test cases. First line: two integers N, M; The following N lines: Every line first comes an integer C(1 <= C <= 100), represents the number of 1s in this row, then comes C integers: the index of the columns whose value is 1 in this row.

Output

First output the number of rows in the selection, then output the index of the selected rows. If there are multiply selections, you should just output any of them. If there are no selection, just output "NO".

Sample Input

6 73 1 4 72 1 43 4 5 73 3 5 64 2 3 6 72 2 7

Sample Output

3 2 4 6

HINT

 

Source

dupeng

 

1 #include
2 #include
3 #include
4 5 using namespace std; 6 7 const int N=1010; 8 const int V=1000010; 9 10 int U[V],D[V]; 11 int L[V],R[V]; 12 int C[V]; 13 int H[N],S[N],mark[V]; 14 int size,n,m,vis[N],flag; 15 16 void Link(int r,int c){ 17 S[c]++;C[size]=c; 18 U[size]=U[c];D[U[c]]=size; 19 D[size]=c;U[c]=size; 20 if(H[r]==-1) 21 H[r]=L[size]=R[size]=size; 22 else{ 23 L[size]=L[H[r]]; R[L[H[r]]]=size; 24 R[size]=H[r]; L[H[r]]=size; 25 } 26 mark[size]=r; 27 size++; 28 } 29 30 void remove(int c){ //删除列 31 L[R[c]]=L[c]; 32 R[L[c]]=R[c]; 33 int i,j; 34 for(i=D[c];i!=c;i=D[i]) 35 for(j=R[i];j!=i;j=R[j]){ 36 U[D[j]]=U[j],D[U[j]]=D[j]; 37 S[C[j]]--; 38 } 39 } 40 41 void resume(int c){ 42 int i,j; 43 for(i=U[c];i!=c;i=U[i]) 44 for(j=L[i];j!=i;j=L[j]){ 45 U[D[j]]=j,D[U[j]]=j; 46 S[C[j]]++; 47 } 48 L[R[c]]=c; 49 R[L[c]]=c; 50 } 51 52 void Dance(int k){ 53 int i,j,min,c; 54 if(!R[0]){ 55 flag=1; 56 printf("%d",k); 57 for(i=0;i

 

转载地址:http://ejpol.baihongyu.com/

你可能感兴趣的文章
【mysql】备份篇2:使用java程序定期备份mysql数据库
查看>>
BZOJ 4514: [Sdoi2016]数字配对 [费用流 数论]
查看>>
mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法
查看>>
Tooltip浮动提示框效果(掌握里面的小知识)
查看>>
getline函数(精华版)
查看>>
myeclipse debug不显示变量值解决的方法
查看>>
Cygwin-Cygwin ssh Connection closed by ::1 出错
查看>>
SpringMVC工作原理
查看>>
【NLP】文本相似度
查看>>
python模拟Get请求保存网易歌曲的url
查看>>
Gson 解析教程
查看>>
曼-惠特尼U检验Mann–Whitney U Test
查看>>
Android 常用动画之RotateAnimation
查看>>
使用 video.js 开发 HTML5 视频页面
查看>>
Go --- 设计模式(模板模式)
查看>>
Java中的日期和时间
查看>>
git命令-切换分支
查看>>
小米手机会不会更好
查看>>
linux免密码登录
查看>>
JS比较两个数组是否相等 是否拥有相同元素
查看>>