Http://codeforces.com/problemset/problem/566/F
Main Topic
:
There are n points, the points have a value of a[i], any two points (I, J) have no direction to the edge when and only if
(A[i] MoD a[j]) ==0| | (A[j] MoD a[i]) ==0
Ask what is the maximum connected sub-graph in this picture.
Idea: direct transfer, TIME complexity O (n^1.5)
#include <cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<iostream>intn,a[2000005],f[2000005];intRead () {intt=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} returnt*F;}intMain () {n=read ();intmx=0; for(intI=1; i<=n;i++) {A[i]=read (); MX=Std::max (Mx,a[i]); } std::sort (A+1, A +1+N); intans=0; for(intI=1; i<=n;i++) {F[a[i]]++; for(intj=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