Codeforces 264B. Good Sequences
題意:稱遞增的且相鄰數不互質的數列為好數列,給出一個數列,求出最長的好數列子列長度
例如 [2 4 6 9] [2 6 10 15 21] …etc
思路:建立一個二維陣列,維護每個數的因子和它自己,然後遍歷數列中每個數字,並且更新每個因子目前的最長值,每步都更新一次最大值作為答案
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
vector<int> s[maxn+5];
int k=1;
void solve()
{
for(int i=2;i<=maxn;i++)
{
if(!s[i].size())
{
for(int j=i;j<=maxn;j+=i)s[j].push_back(i);
}
}
}
int a[maxn];
int dp[maxn];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
solve();
for(int i=1;i<=n;i++){
cin>>a[i];
}
int ans=0;
for(int i=1;i<=n;i++){
int ii=a[i];
int cur=1;
for(int j=0;j<s[ii].size();j++){
cur=max(cur,dp[s[ii][j]]+1);
}
ans=max(ans,cur);
for(int j=0;j<s[ii].size();j++){
dp[s[ii][j]]=max(dp[s[ii][j]],cur);
}
}
cout<<ans<<endl;
}
相關文章
- Bracket Sequences IIRacket
- 013 Three Div Sequences
- D. Invertible Bracket SequencesRacket
- Codeforces Good Bye 2017 C. New Year and Curling(運用數學解析幾何的知識判斷)Go
- Number of k-good subarraysGo
- Some good websites for C++GoWebC++
- 1512. Number of Good PairsGoAI
- Good site on Oracle tech blogGoOracle
- ARC100D/F Colorful Sequences
- rember me all time good luckREMGo
- CF1762F Good PairsGoAI
- CF1925D Good TripGo
- [ARC159F] Good DivisionGo
- [ABC292G] Count Strictly Increasing Sequences
- ABC 312D題 Count Bracket SequencesRacket
- ABC 328F Good Set QueryGo
- [20181007]Scalable sequences oracle database 12c.txtOracleDatabase
- 題解 CF997E 【Good Subsegments】Go
- This is a good question,初學者都犯暈!Go
- 淺談Kotlin中的Sequences原始碼解析(十)Kotlin原始碼
- 얘랑 있을 때 좋다 Good to be with YouGo
- Codeforces
- 題解:AT_abc367_c [ABC367C] Enumerate Sequences
- 9.11 codeforces
- CodeForces 1307
- 論文筆記:What makes instance discrimination good for transfer learning?筆記Go
- 【CodeForces訓練記錄】Codeforces Global Round 27
- 翻譯:《實用的Python程式設計》02_04_SequencesPython程式設計
- cf900D. Unusual Sequences(容斥 莫比烏斯反演)
- [譯]Kotlin中是應該使用序列(Sequences)還是集合(Lists)?Kotlin
- 組會學習(第3周)--Subspace Clustering via Good NeighborsGo
- codeforces 11/10
- Codeforces Round 955
- Codeforces 專區
- CodeForces 1935A
- Codeforces - Jzzhu and Numbers
- codeforces Photo of The Sky
- 【CodeForces訓練記錄】Codeforces Round 991 (Div. 3)