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的更多相关文章

  1. 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\)最大 ...

  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 - 527D Clique Problem (图,贪心)

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

  5. CodeForces 505B Mr. Kitayuta's Colorful Graph

    Mr. Kitayuta's Colorful Graph Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  6. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  7. Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化

    C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...

  8. Codeforces 527D Clique Problem

    http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...

  9. codeforces 505B Mr. Kitayuta's Colorful Graph(水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Mr. Kitayuta's Colorful Graph Mr. Kitayut ...

随机推荐

  1. SDL2.0教程翻译·目录

    原文地址:SDL 2.0 Tutorial Index Welcome! 下面的教程旨在为你提供一个SDL2.0以及c++中游戏设计和相关概念的介绍.在本教程中,我们假定你对C++有一定程度上的知识, ...

  2. Android调用第三方应用

    Intent intent=new Intent(); //包名 包名+类名(全路径) intent.setClassName("com.qn.app.store", " ...

  3. Storm拓扑的并行度(parallelism)介绍

    Storm拓扑的并行度(parallelism)介绍 1.Storm分为3个主要实体,用于在Storm集群中运行拓扑        工作进程:Worker Process,也称为Worker      ...

  4. IT项目外包有哪些注意事项

    2015年两会上,李克强总理在政府工作报告中首次提出“互联网+”计划,各种互联网创业项目也如雨后春笋般破土而出.由于很多创业团队并没有自己的技术团队,所以软件外包成为很多创业项目普遍采取的一种方案.在 ...

  5. 《图解HTTP》 第11章 web的攻击技术

    11.1 针对Web的攻击技术 简单的HTTP协议本身并不存在安全性问题,所以协议本身几乎不会成为攻击的对象. 11.1.1 HTTP不具备必要的安全功能 11.1.2 在客户端即可篡改请求 在HTT ...

  6. 重写boost内存池

    最近在写游戏服务器网络模块的时候,需要用到内存池.大量玩家通过tcp连接到服务器,通过大量的消息包与服务器进行交互.因此要给每个tcp分配收发两块缓冲区.那么这缓冲区多大呢?通常游戏操作的消息包都很小 ...

  7. MAC安装SVNServer

    MAC已经自带了SVN,所以,直接使用就好 1.创建svn repository svnadmin create /path/svn/pro  //仓库位置,svn是svn的目录,pro是一个版本库的 ...

  8. 导航条上UIBarButtonItem的更改方法(使用initWithCustomView:btn)

    UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:self.newMe ...

  9. Myeclipse7.5 下载 安装 注冊 注冊码 100%成功

    myeclipse7.5启动画面 1.下载Myeclipse官方原版 官方原版:或者 http://downloads.myeclipseide.com/downloads/products/ewor ...

  10. Qt 域名转成IP

    #include <stdio.h>#include <stdlib.h>#include <netdb.h>#include <arpa/inet.h> ...