Divisibility

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 
System Crawler  (2015-04-10)

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!
 

Input

An integer t,indicating the number of testcases, 
For every case, first a number n indicating daizhenyang has writen n numbers(n<=1000),then n numbers,all in the range of (1...2^63-1). 
 

Output

The most number you can choose.
 

Sample Input

1
3
1 2 3
 

Sample Output

2

Hint:
If we choose 2 and 3,one is not divisible by the other,which is the most number you can choose.

 
 
 
错了好久啊,DLX理解还是不够深。移除的时候当前行不要移除,要保持联系这样才能左右移动,还加了个剪枝函数进去,若剩下的列加上已取的列小于答案值那么就不再取了。
 #include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
using namespace std; const int HEAD = ;
const int SIZE = * ; int N,ANS;
int U[SIZE],D[SIZE],L[SIZE],R[SIZE],C[]; void ini(void);
void dancing(int);
void remove(int);
void resume(int);
int cut(void);
void debug(int);
int main(void)
{
int t;
long long s[]; //freopen("txt.txt","r",stdin);
scanf("%d",&t);
while(t --)
{
scanf("%d",&N);
for(int i = ;i <= N;i ++)
scanf("%lld",&s[i]); ini();
int count = N + ;
for(int i = ;i <= N;i ++)
{
int first = count;
for(int j = ;j <= N;j ++)
if(s[i] % s[j] == || s[j] % s[i] == )
{
U[count] = U[j];
D[count] = j;
L[count] = count - ;
R[count] = count + ; D[U[count]] = count;
U[j] = count;
C[count] = j; count ++;
}
L[first] = count - ;
R[count - ] = first;
}
dancing();
printf("%d\n",ANS);
} return ;
} void ini(void)
{
ANS = ;
R[HEAD] = ;
L[HEAD] = N;
for(int i = ;i <= N;i ++)
{
L[i] = i - ;
R[i] = i + ;
U[i] = D[i] = C[i] = i;
}
R[N] = ;
} void dancing(int k)
{
if(k + cut() <= ANS)
return ;
if(R[HEAD] == HEAD)
{
ANS = ANS > k ? ANS : k;
return ;
} int c = R[HEAD]; for(int i = D[c];i != c;i = D[i])
{
remove(i);
for(int j = R[i];j != i;j = R[j])
remove(j);
dancing(k + );
for(int j = L[i];j != i;j = L[j])
resume(j);
resume(i);
} return ;
} 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]] = i;
R[L[i]] = i;
}
} void debug(int count)
{
for(int i = ;i <= count;i ++)
printf("U[%d]=%d D[%d]=%d L[%d]=%d R[%d]=%d c[%d]=%d\n",i,U[i],i,D[i],i,L[i],i,R[i],i,C[i]);
return ;
} int cut(void)
{
int sum = ;
for(int i = R[HEAD];i;i = R[i])
sum ++;
return sum;
}

HDU 3335 Divisibility (DLX)的更多相关文章

  1. HDU 3335 Divisibility dancing links 重复覆盖

    分析: dlx重复覆盖的巧用,重复覆盖的原理恰好符合本题的筛选方式,即选择一个数后,该数的倍数或约数可以保证在之后的搜索中不会被选择 于是修改一下启发函数,求解最大的重复覆盖即可.   其实不一定不被 ...

  2. (中等) HDU 3335 , DLX+重复覆盖。

    Description As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory. ...

  3. HDU 5046 Airport(dlx)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5046 题意:n个城市修建m个机场,使得每个城市到最近进场的最大值最小. 思路:二分+dlx搜索判定. ...

  4. HDU 3335

    http://acm.hdu.edu.cn/showproblem.php?pid=3335 题意:在给出的n个数中找出一个集合,使得其中的数互不整除,求该集合最大的元素数量 首先要对输入的数去重,输 ...

  5. hdu 5046 二分+DLX模板

    http://acm.hdu.edu.cn/showproblem.php?pid=5046 n城市建k机场使得,是每个城市最近机场的距离的最大值最小化 二分+DLX 模板题 #include < ...

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

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

  7. 最小路径覆盖 hdu 1151 hdu 3335

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  8. HDU 3656 二分+dlx判定

    Fire station Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  9. HDU 2295 Radar (DLX + 二分)

    Radar Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

随机推荐

  1. COS回应7大质疑

    Apple过于封闭,没啥朋友,这家伙应该比较高傲,曾和Intel,IBM and so on..一起玩过!Google过于开放,狐朋狗友,友人泛滥,殃及ecosystem,弊端已显,祸水将至.COS奉 ...

  2. homework-04

    1.准备工作 本次结对编程我们对项目本身就行了分工,既然是测试来驱动开发,那么我们就把本次工作分成了测试与生成两个部分,小明同学负责生成测试数据,而我写测试程序检测测试结果是否正确,相对来说还是小明同 ...

  3. Android实例-屏幕操持常亮(XE8+小米2)

    相关资料: http://www.bubuko.com/infodetail-163304.html 结果: 1.打开权限Wake lock为True. 第三方单元: unit Android.JNI ...

  4. Scala List的排序函数sortWith

    //原始方法: //val list=List("abc","bcd","cde") scala> list.sortWith( (s ...

  5. Hql处理日期格式化问题

    1. Date date=Calendar.getInstance().getTime(); Date date1=Calendar.getInstance().getTime(); String h ...

  6. 蓝底白字到图形界面 主板BIOS发展简记

    本文转载:http://mb.zol.com.cn/229/2295738.html http://www.360doc.com/content/12/0306/14/1309227_19219857 ...

  7. 教你50招提升ASP.NET性能(十八):在处理网站性能问题前,首先验证问题是否出在客户端

    (29)Before tackling any website performance issue, first verify the problem isn’t on the client 招数29 ...

  8. iOS 判断只有数字、小数点和减号

    #define NUMBERS @"0123456789.-" //数字 #define NUM @"0123456789" //字母 #define ALPH ...

  9. android 表情,软键盘冲突解决方案(仿微博等SNS应用)

    之前总想搞一下这个模块,可是由于忙碌总是推迟,现在就把这块好好的弥补过来,下面是我实现的思路.本人才疏学浅,还望大家不要见笑. 首先我们还是先看写示例:            上面应用应该不用我过多介 ...

  10. 教你使用Android SDK布局优化工具layoutopt

    创建好看的Android布局是个不小的挑战,当你花了数小时调整好它们适应多种设备后,你通常不想再重新调整,但笨重的嵌套布局效率往往非常低下,幸运的是,在Android SDK中有一个工具可以帮助你优化 ...