Codeforces 566 F. Clique in the divisibility Graph

Source: Internet
Author: User

Codeforces 566F Portal

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

Just in case, let us remind-a clique in a non-directed graph is a subset of the vertices of a graph, such this an Y. Vertices of this subset is connected by an edge. In particular, an empty set of vertexes and a set consisting of a vertex, is 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 is numbers from set A, and the numbers AI and AJ (I?≠?J) is connected by an edge if and Only if either AI was divisible by AJ, or AJ is divisible by AI.

You is 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 an 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

The main idea: to ask for an array sequence that requires the longest multiplying sequence such as 3 6 18.

Problem-Solving ideas: DP value,, see the code:

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>Const intN =1e6+Ten;using namespace STD;intDp[n], A;intMain () {intN, MAXN; while(~scanf("%d", &n)) {memset(DP,0,sizeof(DP)); MAXN =0; for(inti =0; I < n; i++) {scanf("%d", &a);            dp[a]++; MAXN = Max (MAXN, Dp[a]); for(intj = A *2; J <= N;        J + = a) dp[j] = max (Dp[j], dp[a]); }printf("%d\n", MAXN); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 566 F. Clique in the divisibility Graph

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.