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 ...
随机推荐
- MFC中DoDataExchange()的作用
void CDlgSelectCS::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Te ...
- 百度贴吧的网络爬虫(v0.4)源码及解析
更新:感谢评论中朋友的提醒,百度贴吧现在已经改成utf-8编码了吧,需要把代码中的decode('gbk')改成decode('utf-8'). 百度贴吧的爬虫制作和糗百的爬虫制作原理基本相同,都 ...
- JDBC之ResultSet
ResultSet is a interface More gnerally,ResultSet is a class involves a table returned by executeQuer ...
- Nmon 监控 Linux 的系统性能
Nmon(得名于 Nigel 的监控器)是IBM的员工 Nigel Griffiths 为 AIX 和 Linux 系统开发的一款计算机性能系统监控工具.Nmon 可以把操作系统的统计数据展示在屏幕上 ...
- paip.输入法编程---增加码表类型
paip.输入法编程---增加码表类型 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attil ...
- linux命令-查看当前目录下所有文件的大小:“ll -h”
//ll -h 命令只会显示文件的大小,而文件夹及其子目录或文件的大小不会显示.[root@hadoop01 soft]# ll -h total 2.1G -rw-r--r--. 1 root ro ...
- [原创]安卓使用Termux做渗透测试(演示sqlmap安装,并附上一个神器)
由于手机kali太大,并且MIUI8+Android6.0的我.用手机kali不是太方便(懒得捣鼓),所以另找道路,用手机作渗透测试. 1.下载一个Termux,并授予ROOT权限. 2.打开之后输入 ...
- Android较低版本(<5.2) 页面默认Select选择框效果的BUG解决
Bug描述: 使用低版本安卓(<5.2),在微信上打开网页,点击下拉框,会出现如下图所示的用来展示select选项的弹出框: 在选项较少的时候,可以向下滑动,将选项滑到底部 滑动前: 滑动后: ...
- 【iOS之runtime、runloop】
什么是runtime runtime就是运行时,是系统在运行时的一些动态机制,它是一套底层的API,我们平时编写的OC代码,最终会转换为runtime实现. runtime的作用 可以利用runtim ...
- Accordion( 分类) 组件
一. 加载方式 //class 加载方式<div id="box" class="easyui-accordion"style="width:3 ...