Codeforces.566F.Clique in the Divisibility Graph(DP)
\(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)的更多相关文章
- Codeforces 566F Clique in the Divisibility Graph
http://codeforces.com/problemset/problem/566/F 题目大意: 有n个点,点上有值a[i], 任意两点(i, j)有无向边相连当且仅当 (a[i] mod a ...
- F. Clique in the Divisibility Graph DP
http://codeforces.com/contest/566/problem/F F. Clique in the Divisibility Graph time limit per test ...
- 周赛-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 ...
- Codeforces 219D. Choosing Capital for Treeland (树dp)
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...
- CodeForces - 527D Clique Problem (图,贪心)
Description The clique problem is one of the most well-known NP-complete problems. Under some simpli ...
- [CodeForces - 1272D] Remove One Element 【线性dp】
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...
- Codeforces 459E Pashmak and Graph(dp+贪婪)
题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35 36组数据 ...
- 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 ...
随机推荐
- Python序列化与反序列化-json与pickle
Python序列化与反序列化-json与pickle 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.json的序列化方式与反序列化方式 1>.json序列化 #!/usr ...
- <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />
代码一:<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> http-eq ...
- transform 属性之 transform-origin与顺序问题
transform属性之 transform-origin 针对transform中的几种值的先后顺序 transform值的先后顺序: 注意: 当我们在旋转后再进行位移的时候,其实是按照旋转后的坐标 ...
- Codeforces 932 E. Team Work(组合数学)
http://codeforces.com/contest/932/problem/E 题意: 可以看做 有n种小球,每种小球有无限个,先从中选出x种,再在这x种小球中任选k个小球的方案数 选出的 ...
- python 基础部分重点复习整理--从意识那天开始进阶--已结
pythonic 风格编码 入门python好博客 进阶大纲 有趣的灵魂 老齐的教程 老齐还整理了很多精华 听说 fluent python + pro python 这两本书还不错! 元组三种遍历, ...
- CSS 编码中超级有用的工具集合
当你开发网站和 Web 应用时,使用合适的工具可以节省大量的时间.本文我将收集一些非常有用的 CSS 编码工具,希望对你有帮助. Pure CSS Pure 是来自雅虎的 CSS 框架,使用 Norm ...
- Linux - awk 文本处理工具二
awk 判断格式 awk '{print ($1>$2)?"第一排"$1:"第二排"$2}' # 条件判断 括号代表if语句判断 "?" ...
- hadoop - hdfs 基础操作
hdfs --help # 所有参数 hdfs dfs -help # 运行文件系统命令在Hadoop文件系统 hdfs dfs -ls /logs # 查看 hdfs dfs -ls /user/ ...
- [BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)
[BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yu ...
- 第9月第27天 AVAssetExportSession AVAssetExportPresetMediumQuality
1. AVAssetExportPresetMediumQuality和 AVAssetExportPreset960x540 码率相差很大,视频大小也会相差很大 AVAssetExportPrese ...