Codeforces 566F Clique in the Divisibility Graph
http://codeforces.com/problemset/problem/566/F
题目大意:
有n个点,点上有值a[i], 任意两点(i, j)有无向边相连当且仅当
(a[i] mod a[j])==0||(a[j] mod a[i])==0
问这幅图中的最大连通子图是多少。
思路:直接转移,时间复杂度O(n^1.5)
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
int n,a[],f[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
n=read();int mx=;
for (int i=;i<=n;i++){
a[i]=read();
mx=std::max(mx,a[i]);
}
std::sort(a+,a++n);
int ans=;
for (int i=;i<=n;i++){
f[a[i]]++;
for (int j=a[i]+a[i];j<=mx;j+=a[i])
f[j]=std::max(f[j],f[a[i]]);
ans=std::max(ans,f[a[i]]);
}
printf("%d\n",ans);
}
Codeforces 566F Clique in the Divisibility Graph的更多相关文章
- 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\)最大 ...
- 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 - 527D Clique Problem (图,贪心)
Description The clique problem is one of the most well-known NP-complete problems. Under some simpli ...
- CodeForces 505B Mr. Kitayuta's Colorful Graph
Mr. Kitayuta's Colorful Graph Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化
C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...
- Codeforces 527D Clique Problem
http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...
- codeforces 505B Mr. Kitayuta's Colorful Graph(水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Mr. Kitayuta's Colorful Graph Mr. Kitayut ...
随机推荐
- 用nginx做代理服务器上网
用nginx做代理服务器上网 目前现状:只有1个机器能上网(web),其他机器不能方法:能上网的做一个代理web服务器中转,其他机器连接它即可.采用nginx Nginx配置如下: server{ ...
- git中的常用指令名及其意义
add 添加新文件到 Git 代码仓库的索引中 $ git add filename mv 移动或重命名文件 $ git mv old-filename new-filename rm 从工作目录和 ...
- Linux系统编程(34)—— socket编程之TCP服务器与客户端的交互
前面几篇中实现的client每次运行只能从命令行读取一个字符串发给服务器,再从服务器收回来,现在我们把它改成交互式的,不断从终端接受用户输入并和server交互. /* client.c */ #in ...
- Java---设计模块(设计模块的简介及最简单的俩个单例代码加测试)
设计模式学习概述: ★ 为什么要学习设计模式 1.设计模式都是一些相对优秀的解决方案,很多问题都是典型的.有代表性的问题,学习设计模式,我们就不用自己从头来解决这些问题,相当于在巨人的肩膀上,复用这些 ...
- HDU_1426——数独问题,DFS
Problem Description 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为一个单独的项目进行 ...
- 多次绑定click及ajax提交常用方法
<script> $(document).ready(function() { //绑定click $(".exchange_ecv").bind("clic ...
- asdasd
adasdasd asdasd asdasd asd
- (转)Linux下Apache 限速模块安装笔记
参考文章:http://www.pcmag.com.cn/solution/net/story/200704/51003104.shtml 限线程:http://dominia.org/djao/li ...
- (转)重置Mac OS X管理员密码
忘记Mac管理员密码怎么办?别担心,办法总会有的. [方法一] 开机按住option,选择Recovery HD(Snow Leopard插入光盘开机按住C) Snow Leopard系统:进入后在上 ...
- android 分辨率自适应
1.术语和概念 术语 说明 备注 Screen size(屏幕尺寸) 指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸 摩托罗拉milestone手机是3.7英寸 A ...