Description

  As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory.So,many people call him "the descendant of Chen Jingrun",which brings him a good reputation. 
  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!
 
  题目就是找到几个数,然后他们之间都不能整除。。。。。。
  这个题卡了一段时间。。。。。。看了大神们的题解之后才会的。。。。。。
  虽然这个题目让我们求得是最大值,其实是在最小值里面的最大值,DLX可重复覆盖的模板是为了找到最小值,所以找到最小值的过程中默认了选择某一个之后和他相关连的都不用在选择了。。。而这样正好就符合了这个题目的要求,也就是我们以找最小值的方法,找到的值就是符合题意的一个值。。。。。。然后改一下getH()函数,也就是获得启发值得函数,就OK了。。。
  构造的话就是n行n列就好,代表这n个数,(所以要求每一列都要被覆盖掉。。。。。。)。。。。。。
 
代码如下:
#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+重复覆盖。的更多相关文章

  1. (中等) HDU 2295 , DLX+重复覆盖+二分。

    Description N cities of the Java Kingdom need to be covered by radars for being in a state of war. S ...

  2. hdu 2295 dlx重复覆盖+二分答案

    题目大意: 有一堆雷达工作站,安放至多k个人在这些工作站中,找到一个最小的雷达监控半径可以使k个工作人所在的雷达工作站覆盖所有城市 二分半径的答案,每次利用dlx的重复覆盖来判断这个答案是否正确 #i ...

  3. HDU 5046 Airport【DLX重复覆盖】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意: 给定n个城市的坐标,要在城市中建k个飞机场,使城市距离最近的飞机场的最长距离最小,求这 ...

  4. HDU 2295.Radar (DLX重复覆盖)

    2分答案+DLX判断可行 不使用的估计函数的可重复覆盖的搜索树将十分庞大 #include <iostream> #include <cstring> #include < ...

  5. HDU 3957 Street Fighter (最小支配集 DLX 重复覆盖+精确覆盖 )

    DLX经典题型,被虐惨了…… 建一个2*N行3*N列的矩阵,行代表选择,列代表约束.前2*N列代表每个人的哪种状态,后N列保证每个人至多选一次. 显然对手可以被战胜多次(重复覆盖),每个角色至多选择一 ...

  6. HDU 2295 Radar 重复覆盖 DLX

    题意: N个城市,M个雷达站,K个操作员,问雷达的半径至少为多大,才能覆盖所有城市.M个雷达中最多只能有K个同时工作. 思路: 二分雷达的半径,看每个雷达可以覆盖哪些城市,然后做重复覆盖,判断这个半径 ...

  7. [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 ...

  8. hdu3656Fire station(DLX重复覆盖 + 二分)

    题目请戳这里 题目大意:一个城市n个点,现在要建m个消防站,消防站建在给定的n个点中.求建m个消防站后,m个消防站要覆盖所有的n个点的覆盖半径最小. 题目分析:重复覆盖问题,DLX解决.不过要求覆盖半 ...

  9. hdu 3498 whosyourdaddy 重复覆盖

    题目链接 重复覆盖的入门题, 和精确覆盖不一样, 删除的时候只删除一行多列. #include<bits/stdc++.h> using namespace std; #define pb ...

随机推荐

  1. idea编译器中maven项目获取路径的方法

    资源文件放在哪里? 上 图中的 resources 目录叫资源目录 (main下,与java如果没有请自行创建), 在项目编译后文件会被放到红色的 classes 目录下, 注意如果你的 resour ...

  2. Swift\本地文件管理

    转载自:http://www.coloroud.com/2015/06/01/Swift-File-Manager/ 开头 看来Swift这趟浑水是非干不可,既然如此,那索性就来的彻底吧,来一次全方位 ...

  3. windows程序设计(四)

    对话框常用相关消息映射函数: 一.对话框初始化消息: 1.WM_CREATE:通用窗口初始化消息 窗口还未显示出来,只有父窗口,子窗口还没创建 2.WM_INITDIALOG:对话框窗口专用消息 子窗 ...

  4. HDU1253--胜利大逃亡--HDU1240--Asteroids!--简单三维BFS

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  5. 编译filezilla

    编译zilla的时候,需要用到与mysql连接的地方(这里先忽略zila的编译) VC听过mysql connector c++, 下载了1.1.3版本,然后飞安装包,之后从官网上下载boost 把库 ...

  6. Pro/TOOLKIT入门教程汇总

    手把手教你开发Pro/TOOLKIT应用程序 手把手教你开发Pro/TOOLKIT应用程序(一) 手把手教你开发Pro/TOOLKIT应用程序(二) 手把手教你开发Pro/TOOLKIT应用程序(三) ...

  7. JSP标准标签库(JSTL)--SQL标签库 sql

    了解即可.SQL标签库 No. 功能分类 标签名称 描述 1 数据源标签 <sql:setDataSource> 设置要使用的数据源名称 2 数据库操作标签 <sql:query&g ...

  8. DFS序的题目列表

    所谓dfs序就是将之前的顺序进行修改,获得一个新的序列,然后再新的序列下进行一系列其他的操作 一般题目给你的都会是一棵树,然后点之间都是无关的,我们首要的任务就是先把这些序列重新排.然后再根据dfs的 ...

  9. rstPixelType Constants

    Constant Value Description PT_UNKNOWN -1 Pixel values are unknown. PT_U1 0 Pixel values are 1 bit. P ...

  10. C# Guid用法

    GUID(全局统一标识符)是指在一台机器上生成的数字,它保证对在同一时空 中的所有机器都是唯一的.通常平台会提供生成GUID的API.生成算法很有意思,用到了以太网卡地址.纳秒级时间.芯片ID码和许多 ...