Codeforces 566 F. Clique in the Divisibility Graph

Codeforces 566F 的传送门

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 = {a1, a2, …, an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i ≠ j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.

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

Input

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

The second line contains n distinct positive integers a1, a2, …, an (1 ≤ ai ≤ 106) — elements of subset A. The numbers in the line follow in the ascending order.

Output

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

Sample test(s)

Input
8
3 4 6 8 10 18 21 24

Output
3

题目大意:,要求,给出一个数组序列,要求最长的成倍增长的序列如 3 6 18等。

解题思路:dp值,,,详见代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
const int N = 1e6+10;
using namespace std;

int dp[N], a;

int main()
{
    int n, maxn;
    while(~scanf("%d", &n))
    {
        memset(dp, 0, sizeof(dp));
        maxn = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%d", &a);
            dp[a]++;
            maxn = max(maxn, dp[a]);
            for(int j = a * 2; j <= N; j += a)
                dp[j] = max(dp[j], dp[a]);
        }
        printf("%d\n", maxn);
    }
}
时间: 2024-08-22 14:38:13

Codeforces 566 F. Clique in the Divisibility Graph的相关文章

基本数据结构(算法导论)与python

Stack, Queue Stack是后进先出, LIFO, 队列为先进先出, FIFO 在python中两者, 都可以简单的用list实现, 进, 用append() 出, Stack用pop(), Queue用pop(0), pop的时候注意判断len(l)  对于优先队列, 要用到前面讲到的堆 链表和多重数组 这些数据结构在python中就没有存在的价值, 用list都能轻松实现 散列表 为了满足实时查询的需求而产生的数据结构, 查询复杂度的期望是O(1), 最差为O(n) 问题描述, 对

ASP.NET MVC验证码功能实现代码_实用技巧

前台 复制代码 代码如下: <img id="vcodeimg" src="/Home/VCode" width="70"                                    height="25" />                                 <span                                    style="cursor: p

python 回溯法 子集树模板 系列 —— 8、图的遍历

问题 一个图: A --> B A --> C B --> C B --> D B --> E C --> A C --> D D --> C E --> F F --> C F --> D 从图中的一个节点E出发,不重复地经过所有其它节点后,回到出发节点E,称为一条路径.请找出所有可能的路径. 分析 将这个图可视化如下: 本问题涉及到图,那首先要考虑图用那种存储结构表示.邻接矩阵.邻接表....都不太熟. 百度一下,在这里发现了一个最爱.

通过wsdl2java工具生成客户端段代码(wsdl2java -p cn.com.css.misps.graph.webservice.impl -d F:\src -all http://10.)

首先当前是从官网下载cxf组件. Java代码 http://cxf.apache.org/download.html  http://cxf.apache.org/download.html 下载后解压,在这里主要是用到解压后的bin目录中的wsdl2java.bat该批处理文件. 可以直接进入bin目下,运行wsdl2java,需要注意的他的几个参数 我测试时直接运行的以下命令: 写道 wsdl2java -p cn.com.css.misps.graph.webservice.impl -

Codeforces 550 C. Divisibility by Eight

C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't conta

Codeforces 597 A. Divisibility 【Testing Round #12】

A. Divisibility time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer valu

Codeforces Round #205 (Div. 2) / 353C Find Maximum (贪心)

Valera has array a, consisting of n integers a0,a1,...,an-1, and function f(x), taking an integer from 0 to 2n-1 as its single argument. Value f(x) is calculated by formula , where value bit(i) equals one if the binary representation of number xconta

算法:CodeForces #196(Div. 2) 337D Book of Evil(树形dp)

题意 给一棵n个结点的树,任意两个节点的距离是指连接两点的最短的边数 在树上的某个结点 有一个"恶魔之书",这本书会让距离它d以内的节点都受到影响 已知有m个节点收到了影响,问最多有几 个结点可能放着"恶魔之书"? 思路 要判断某个点是不是放着书,就要判断这个点的周围d距离以 内是否包含所有受影响的m节点 而如果某个节点距离最远的那个受影响节点的距离是L,如果L <= d,那 么说明所有受影响的m节点都在d以内,就可判断这个点可能放着书 那么,我们只要能够求出

Pregel: A System for Large-Scale Graph Processing

作者Grzegorz Malewicz, Matthew H. Austern .etc.Google Inc 2010-6 原文http://people.apache.org/~edwardyoon/documents/pregel.pdf 译者phylips@bmy 2012-09-14 译文http://duanple.blog.163.com/blog/static/70971767201281610126277/ [说明Pregel这篇是发表在2010年的SIGMOD上Pregel这