zoukankan      html  css  js  c++  java
  • codeforces 566F

    题目链接: https://codeforces.com/problemset/problem/566/F

    最大团即找出能相互整除的最长子序列长度
    (dp[i])表示以 i 结尾的序列能组成的最长子序列长度
    采用刷表法,枚举(a[i])的倍数更新
    时间复杂度:

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<cmath>
    #include<stack>
    #include<queue>
    using namespace std;
    typedef long long ll;
    
    const int maxn = 1000100;
    
    int n;
    int a[maxn],dp[maxn],g[maxn];
    
    ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
    
    int main(){
    	n = read();
    	int mx = 0;
    	for(int i=1;i<=n;++i) a[i] = read(),mx = max(mx,a[i]);
    	
    	sort(a+1,a+1+n);
    	
    	for(int i=1;i<=n;++i){
    		for(int j=2*a[i];j<=mx;j+=a[i]){
    			dp[j] = max(dp[j],dp[a[i]]+1);
    		}
    		++dp[a[i]];
    	}
    //	for(int i=1;i<=n;++i) printf("%d
    ",dp[a[i]]);
    	
    	int ans = 0;
    	for(int i=1;i<=n;++i){
    		ans = max(ans,dp[a[i]]);
    	}
    	
    	printf("%d
    ",ans);
    	
    	return 0;
    }
    
  • 相关阅读:
    朋友
    Music
    Rnadom Teams
    Bone Collector(01背包)
    Common Subsequence LCS
    Copying Books
    Equal Sum Sets
    Checker Challenge
    棋盘问题
    油田(Oil Deposits)
  • 原文地址:https://www.cnblogs.com/tuchen/p/13874182.html
Copyright © 2011-2022 走看看