(中等) HDU 3335 , DLX+重复覆盖。
Description
AekdyCoin also plays an important role in the ACM_DIY group,many people always ask him questions about number theory.One day,all members urged him to conduct a lesson in the group.The rookie daizhenyang is extremely weak at math,so he is delighted.
However,when AekdyCoin tells us "As we know, some numbers have interesting property. For example, any even number has the property that could be divided by 2.",daizhenyang got confused,for he don't have the concept of divisibility.He asks other people for help,first,he randomizely writes some positive integer numbers,then you have to pick some numbers from the group,the only constraint is that if you choose number a,you can't choose a number divides a or a number divided by a.(to illustrate the concept of divisibility),and you have to choose as many numbers as you can.
Poor daizhenyang does well in neither math nor programming.The responsibility comes to you!
#include<iostream>
#include<cstring> using namespace std; const int MaxN=;
const int MaxM=;
const int MaxNode=MaxN*MaxM; struct DLX
{
int L[MaxNode],R[MaxNode],U[MaxNode],D[MaxNode],col[MaxNode];
int H[MaxN],S[MaxM];
int ansnum;
int n,m,size; void init(int _n,int _m)
{
n=_n;
m=_m; for(int i=;i<=m;++i)
{
U[i]=D[i]=i;
L[i]=i-;
R[i]=i+; S[i]=;
}
L[]=m;
R[m]=; size=m; ansnum=; for(int i=;i<=n;++i)
H[i]=-;
} void Link(int r,int c)
{
col[++size]=c;
++S[c]; U[size]=U[c];
D[size]=c;
D[U[c]]=size;
U[c]=size; if(H[r]==-)
H[r]=L[size]=R[size]=size;
else
{
L[size]=L[H[r]];
R[size]=H[r];
R[L[H[r]]]=size;
L[H[r]]=size;
}
} void remove(int c)
{
for(int i=D[c];i!=c;i=D[i])
{
L[R[i]]=L[i];
R[L[i]]=R[i];
}
} void resume(int c)
{
for(int i=U[c];i!=c;i=U[i])
L[R[i]]=R[L[i]]=i;
} int getH()
{
int ret=; for(int i=R[];i!=;i=R[i])
++ret; return ret;
} void Dance(int d)
{
if(R[]==)
if(d>ansnum)
ansnum=d; if(getH()+d<=ansnum)
return; int c=R[]; for(int i=R[];i!=;i=R[i])
if(S[i]<S[c])
c=i; for(int i=D[c];i!=c;i=D[i])
{
remove(i); for(int j=R[i];j!=i;j=R[j])
remove(j); Dance(d+); for(int j=L[i];j!=i;j=L[j])
resume(j); resume(i);
}
} }; DLX dlx;
unsigned long long num[];
int N; void slove()
{
dlx.init(N,N); for(int i=;i<=N;++i)
for(int j=;j<=N;++j)
if(num[i]%num[j]== || num[j]%num[i]==)
dlx.Link(i,j); dlx.Dance(); cout<<dlx.ansnum<<endl;
} int main()
{
ios::sync_with_stdio(false); int T;
cin>>T; while(T--)
{
cin>>N; for(int i=;i<=N;++i)
cin>>num[i]; slove();
} return ;
}
(中等) HDU 3335 , DLX+重复覆盖。的更多相关文章
- (中等) HDU 2295 , DLX+重复覆盖+二分。
Description N cities of the Java Kingdom need to be covered by radars for being in a state of war. S ...
- hdu 2295 dlx重复覆盖+二分答案
题目大意: 有一堆雷达工作站,安放至多k个人在这些工作站中,找到一个最小的雷达监控半径可以使k个工作人所在的雷达工作站覆盖所有城市 二分半径的答案,每次利用dlx的重复覆盖来判断这个答案是否正确 #i ...
- HDU 5046 Airport【DLX重复覆盖】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意: 给定n个城市的坐标,要在城市中建k个飞机场,使城市距离最近的飞机场的最长距离最小,求这 ...
- HDU 2295.Radar (DLX重复覆盖)
2分答案+DLX判断可行 不使用的估计函数的可重复覆盖的搜索树将十分庞大 #include <iostream> #include <cstring> #include < ...
- HDU 3957 Street Fighter (最小支配集 DLX 重复覆盖+精确覆盖 )
DLX经典题型,被虐惨了…… 建一个2*N行3*N列的矩阵,行代表选择,列代表约束.前2*N列代表每个人的哪种状态,后N列保证每个人至多选一次. 显然对手可以被战胜多次(重复覆盖),每个角色至多选择一 ...
- HDU 2295 Radar 重复覆盖 DLX
题意: N个城市,M个雷达站,K个操作员,问雷达的半径至少为多大,才能覆盖所有城市.M个雷达中最多只能有K个同时工作. 思路: 二分雷达的半径,看每个雷达可以覆盖哪些城市,然后做重复覆盖,判断这个半径 ...
- [ACM] HDU 2295 Radar (二分法+DLX 重复覆盖)
Radar Problem Description N cities of the Java Kingdom need to be covered by radars for being in a s ...
- hdu3656Fire station(DLX重复覆盖 + 二分)
题目请戳这里 题目大意:一个城市n个点,现在要建m个消防站,消防站建在给定的n个点中.求建m个消防站后,m个消防站要覆盖所有的n个点的覆盖半径最小. 题目分析:重复覆盖问题,DLX解决.不过要求覆盖半 ...
- hdu 3498 whosyourdaddy 重复覆盖
题目链接 重复覆盖的入门题, 和精确覆盖不一样, 删除的时候只删除一行多列. #include<bits/stdc++.h> using namespace std; #define pb ...
随机推荐
- C#后台绑定ComboBox
C# using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...
- Win32 SDK Combo Box
如下图所示,显示了三种不同风格的Combo Box样式.当然,现在这样看不出第一种与第三种之间的区别,但是第二种与其他两种的区别是明显的,第二种的列表框始终是出于现实状态的. Combo Box: 一 ...
- OpenGL一些函数详解(二)
OpenGL ES顶点数据绘制技巧 在OpenGL中,绘制一个长方体,需要将每个顶点的坐标放在一个数组中.保存坐标时有一些技巧(由于字母下标不好表示,因此将下标表示为单引号,如A1将在后文中表示为A' ...
- ubuntu下安装多个jdk的切换命令update-alternatives
update-alternatives 以前叫alternatives 下面的介绍,直接引用了,其中必须安装了才会在候选里面出现. usage: update-alternatives --inst ...
- jenkins插件 build-name-setter
#${BUILD_NUMBER}-${PROJECT_NAME}-${ENV,var="VARIABLENAME"}-${ENV,var="BUILD_USER" ...
- 解决 UNMOUNTABLE_BOOT_VOLUME 蓝屏【转载】
现象:一台XP系统的机器,开机在滚动条阶段蓝屏,蓝屏代码大概是“UNMOUNTABLE_BOOT_VOLUME”. 用PE进系统后发现C盘的文件格式变为RAW,总容量等变为0 解决方法一:将故障机的硬 ...
- elasticsearch 索引优化
ES索引优化篇主要从两个方面解决问题,一是索引数据过程:二是检索过程. 索引数据过程我在上面几篇文章中有提到怎么创建索引和导入数据,但是大家可能会遇到索引数据比较慢的过程.其实明白索引的原理就可以有 ...
- C#实现http断点下载
我们寄希望于万能的解决方案,但是现实的情况总是很糟糕.在软件编程的世界中,技术分散的情况尤为严重,且不说各种语言拥有的优势不能融合,单就一门语言而言,就拥有众多的技术和相关技术需要学习.网络编程就是这 ...
- JS的数据类型转换
JS 数据类型转换 方法主要有三种 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后者把 ...
- DP CF 319 div1B
http://codeforces.com/contest/319/problem/B 题目大意: 有删除操作,每次都删除数组右边比自己小的.且紧挨着自己的数字.问最小需要删除几次. 思路: 我们定义 ...