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中的列表解析和生成器表达式
Python中的列表解析和生成器表达式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.列表解析案例 #!/usr/bin/env python #_*_coding:utf-8 ...
- 使用Python的turtle(海龟)模块画图
第一步:让Python引入turtle模块,引入模块就是告诉Python你想要用它. import turtle 第二步:创建画布.调用turtle中的Pen函数 t = turtle.Pen() 第 ...
- 51Nod 1684 子集价值 (平方和去括号技巧)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1684 题意: 新建一个位运算,求所有子集通过这个位运算后的答案的平方和是 ...
- 高品质的JavaScript
整理书籍内容(QQ:283125476 发布者:M [重在分享,有建议请联系->QQ号]) 养成良好的编程习惯 ##如何避免团队JS冲突 * 避免实用全局变量[可使用匿名函数进行处理]以避免全局 ...
- [机器学习&数据挖掘]机器学习实战决策树plotTree函数完全解析
在看机器学习实战时候,到第三章的对决策树画图的时候,有一段递归函数怎么都看不懂,因为以后想选这个方向为自己的职业导向,抱着精看的态度,对这本树进行地毯式扫描,所以就没跳过,一直卡了一天多,才差不多搞懂 ...
- shell 判断为空打印
判断参数是否为空-空退出并打印null #!/bin/sh echo $ name=${:?"null"} echo $name
- 【洛谷P3884 [JLOI2009]】二叉树问题
题目描述 如下图所示的一棵二叉树的深度.宽度及结点间距离分别为: 深度:4 宽度:4(同一层最多结点个数) 结点间距离: ⑧→⑥为8 (3×2+2=8) ⑥→⑦为3 (1×2+1=3) 注:结点间距离 ...
- HDU 4506 小明系列故事——师兄帮帮忙(二分快速幂)
题意:就是输入一个数组,这个数组在不断滚动,而且每滚动一次后都要乘以一个数,用公式来说就是a[i] = a[i-1] * k;然后最后一位的滚动到第一位去. 解题报告:因为题目中的k要乘很多次,达到了 ...
- HDU 1241 Oil Deposits DFS搜索题
题目大意:给你一个m*n的矩阵,里面有两种符号,一种是 @ 表示这个位置有油田,另一种是 * 表示这个位置没有油田,现在规定相邻的任意块油田只算一块油田,这里的相邻包括上下左右以及斜的的四个方向相邻的 ...
- 正则匹配URL地址
import re u = "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]) ...