CodeForces - 566F

很好的一道题,欧拉筛与dp的结合

也可以理解为刷表法

具体解法没什么好说的,一看代码就明白了

#include<bits/stdc++.h>
using namespace std;
//#define int long long
//#define F first
//#define S second
#define endl "\n"
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 1000000+5
int n;
int a[N],f[N];
main()
{
    IO;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        f[a[i]]++;
    }
    int mx=0;
    for(int i=1;i<=1000000;i++){
        if(f[i]!=0){
            for(int j=2;i*j<=1000000;j++)
                if(f[i*j]!=0) f[i*j]=max(f[i*j],f[i]+1);
            mx=max(mx,f[i]);
        }
    }
    cout<<mx<<endl;
}

  

posted on 2019-02-05 21:44  欣崽  阅读(403)  评论(0)    收藏  举报

导航