题目链接

\(Description\)

给定集合\(S=\{a_1,a_2,\ldots,a_n\}\),集合中两点之间有边当且仅当\(a_i|a_j\)或\(a_j|a_i\)。

求\(S\)最大的一个子集\(S'\),并满足\(S'\)中任意两点间都有连边(\(S'\)中只有1个点也是合法的)。

\(n,a_i\leq 10^6\),\(a_i\)互不相同。

\(Solution\)

从小到大选(已经排好序),如果选了\(a_i\),则下一个数一定是\(a_i\)的倍数,下下个数一定是下个数和这个数的倍数。。

容易想到DP,每次更新其倍数即可。

复杂度。。好像不是\(O(n\ln n)\)吧?哦,看漏了个\(a_i\)互不相同。。

那\(a_i\)可相同就有趣了。

算了。。怎么着都能被卡到\(O(n^2)\)。。

#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=1e6+5; int n,A[N],f[N]; inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
} int main()
{
n=read(); int mx=0, ans=1;
for(int i=1; i<=n; ++i) mx=std::max(mx,A[i]=read());
for(int i=1; i<=n; ++i)
{
int a=A[i], v=++f[a];
ans=std::max(ans,v);
for(int j=a<<1; j<=mx; j+=a) f[j]=std::max(f[j],v);
}
printf("%d\n",ans); return 0;
}

Codeforces.566F.Clique in the Divisibility Graph(DP)的更多相关文章

  1. Codeforces 566F Clique in the Divisibility Graph

    http://codeforces.com/problemset/problem/566/F 题目大意: 有n个点,点上有值a[i], 任意两点(i, j)有无向边相连当且仅当 (a[i] mod a ...

  2. F. Clique in the Divisibility Graph DP

    http://codeforces.com/contest/566/problem/F F. Clique in the Divisibility Graph time limit per test ...

  3. 周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏

    Clique in the Divisibility Graph time limit per test1 second memory limit per test256 megabytes inpu ...

  4. Codeforces 219D. Choosing Capital for Treeland (树dp)

    题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...

  5. CodeForces - 527D Clique Problem (图,贪心)

    Description The clique problem is one of the most well-known NP-complete problems. Under some simpli ...

  6. [CodeForces - 1272D] Remove One Element 【线性dp】

    [CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...

  7. Codeforces 459E Pashmak and Graph(dp+贪婪)

    题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...

  8. Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP

    http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35  36组数据 ...

  9. codeforces 459E E. Pashmak and Graph(dp+sort)

    题目链接: E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. 读书笔记:《思考的乐趣:Matrix67数学笔记》第4章 统计数据的陷阱

    <思考的乐趣:Matrix67数学笔记>第4章讲了几个统计学上的陷阱,由于现在流行的大数据与统计学很有渊源,所以认真读了这一章,在<大数据时代>中指出只考虑相关性就够了,而不考 ...

  2. dede调用多级导航的方法

    <div id="navWrapper"> <div class="content"> <ul class="nav m ...

  3. [整理]C 内核源代码-学习资料

    GNU C gnu项目:http://www.gnu.org/software/software.html ftp:http://ftp.gnu.org/gnu/ 托管:http://savannah ...

  4. spring Mvc Web 编码相关 [model 到 视图传递数据] (九)

    在某种编码环境,由bean注解的参数可能会发生乱码问题. 即可页面web.xml或其他地方都设备UTF-8, 但还是会有这样的问题. 首先不要使用model传到视图的数据. 第二,不要request. ...

  5. AngularJs -- 模 块

    在JavaScript中,将函数代码全部定义在全局命名空间中绝对不是什么好主意,这样做会导致冲突从而是调试变得非常困难,浪费宝贵的时间. 上一章介绍数据绑定时,就是写在全局命名空间中定义的函数. 在A ...

  6. CentOS 编译 GCC 7.2

    CentOS 编译 GCC 7.2 下载源码 wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-7.2.0/gcc-7.2.0. ...

  7. shell 判断路径

    判断路径 ];then echo "找到了123" if [ -d /root/Desktop/text ] then echo "找到了text" else ...

  8. Python3之外部文件调用Django程序操作model等文件实现

    import os import sys import django sys.path.append(r'C:\Users\Administrator\PycharmProjects\your pro ...

  9. MYSQL导入数据出现The MySQL server is running with the --secure-file-priv

    MYSQL导入数据出现The MySQL server is running with the --secure-file-priv option so it cannot execute this ...

  10. JDK1.8源码hashMap

    一.概念 允许key为null,value为null:线程不安全:不保证映射的顺序:迭代 collection 视图所需的时间与 HashMap 实例的“容量”(桶的数量)及其大小(键-值映射关系数) ...