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. [iOS 多线程 & 网络 - 2.3] - 解析xml

    A.XML基本知识 1.xml概念 什么是XML全称是Extensible Markup Language,译作“可扩展标记语言”跟JSON一样,也是常用的一种用于交互的数据格式一般也叫XML文档(X ...

  2. 《数据通信与网络》笔记--SCTP

    SCTP(stream control transmission protocol)是一种新的可靠的,面向报文的传输层控制协议.它兼有UDP和TCP的特性,它是可靠的面向报文的协议,它保存报文的边界, ...

  3. CodeForces 548A Mike and Fax (回文,水题)

    题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长. 析:没什么好说的,每次截取n/k个,判断是不是回文就好. 代码如下: #include<bits/stdc++.h&g ...

  4. MySQL Update语句用法

    用一个表的某列值更新另外一个表的某列值的sql语句: update tableA a innner join tableB b on a.column_1 = b.column_1 set a.col ...

  5. update多表更新的2种方式

    update t1 set TermBeginQty =isnull((select top 1 JiaoPlusQty from WMS_RptMaterialPutDaily r where t1 ...

  6. Mac使用指南

    1.csrutil命令 简单来说 是苹果在新系统后加入的一个安全机制. Rootless讨论的前提是假定root账户是OS X(或者其他Unix系统)中对抗恶意程序保护操作系统的最后一道防线.意思是一 ...

  7. Hibernate 中createQuery与createSQLQuery

    本文原址 : http://stta04.javaeye.com/blog/377633 hibernate 中createQuery与createSQLQuery 昨晚帮同事看代码到凌晨2点多,今早 ...

  8. linux杂谈(十八):DNS服务器的配置(一)

    原文地址: http://blog.chinaunix.net/uid-29622064-id-4242123.html 1.DNS服务器简介 域名系统(英文:Domain Name System,縮 ...

  9. iOS有关截图的操作

    1.截取选中view的图片 //根据size大小创建一个基于位图的图形上下文 CGRect rect =view.frame; UIGraphicsBeginImageContext(rect.siz ...

  10. 最小投票BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)

    上班之余抽点时间出来写写博文,希望对新接触的朋友有帮助.今天在这里和大家一起学习一下最小投票 1934: [Shoi2007]Vote 好心的投票 Time Limit: 1 Sec Memory L ...