F. Clique in the divisibility Graph
Topic Transmission: Clique in the divisibility Graph
Solution: Sieve Method +DP
AC Code:
#include <map>#include <set>#include <cmath>#include <deque>#include <queue>#include <stack>#include <cstdio>#include <cctype>#include <string>#include <vector>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL Long Long#define INF 0x7fffffffusing namespace STD;Const intMAXN =1000005;intDP[MAXN];//dp[i] Indicates the maximum size that can be produced by the number ending with I, and the state transfer is performed in the Sieve method.intn, X;intMain () {Cin>> N; for(inti =0; I < n; i + +) {scanf("%d", &x); DP[X] =1; } for(inti =1; i < MAXN; i + +) {if(Dp[i]! =0) for(intj =2I J < Maxn; J + = i) {if(Dp[j]! =0) {Dp[j] = max (Dp[j], Dp[i] +1); } } }intAns =0; for(inti =0; i < MAXN; i + +) {ans = max (ans, dp[i]); }cout<< ans << Endl;return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
VK Cup 2015-finals, online mirror