CF566F.Clique in the Divisibility Graph

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.

Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.

Let's define a divisibility graph for a set of positive integers A = {_a_1, _a_2, ..., a__n} as follows. The vertices of the given graph are numbers from set A, and two numbers a__i and a__j (i ≠ j) are connected by an edge if and only if either a__i is divisible by a__j, or a__j is divisible by a__i.

You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.

众所周知,任意图中的最大团问题是一个 NP-难问题。然而,对于某些特定类型的图,该问题可以被高效地解决。

为防万一,我们来回顾一下:无向图中的一个团是指图中顶点的一个子集,使得该子集中的任意两个顶点之间都存在一条边相连。特别地,空顶点集以及仅含一个顶点的集合也都视为团。

现对一个正整数集合 $ A = {a_1, a_2, \dots, a_n} $ 定义其整除图如下:该图的顶点即为集合 $ A $ 中的各个数;对任意 $ i \ne j $,当且仅当 $ a_i $ 被 $ a_j $ 整除,或 $ a_j $ 被 $ a_i $ 整除时,顶点 $ a_i $ 与 $ a_j $ 之间连有一条边。

现给定一个非负整数集合 $ A $,请确定其整除图中最大团的大小。

输入格式

The first line contains integer n (1 ≤ n ≤ 106), that sets the size of set A.

The second line contains n distinct positive integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 106) — elements of subset A. The numbers in the line follow in the ascending order.

第一行包含一个整数 nn(1≤n≤1061 \leq n \leq 10^6),表示集合 AA 的大小。

第二行包含 nn 个互不相同的正整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \leq a_i \leq 10^6)——即子集 AA 的元素。这些数字在该行中按升序排列。

输出格式

Print a single number — the maximum size of a clique in a divisibility graph for set A.

输出一个整数——集合 AA 的整除图中最大团的大小。

输入输出样例

  • 输入#1

    8
    3 4 6 8 10 18 21 24

    输出#1

    3

说明/提示

In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.

在第一个样例测试中,一个大小为 3 的团(clique)例如是顶点集 {3, 6, 18}\{3,\,6,\,18\}。该图中不存在更大规模的团。

输入解题思路,AI测评打分。不知道怎么写?

首页