CodeForces - 1350B Orac and Models(dp)
生活随笔
收集整理的這篇文章主要介紹了
CodeForces - 1350B Orac and Models(dp)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目鏈接:點擊查看
題目大意:給出一個長度為 n 的數(shù)列,求出最長上升子序列的長度,滿足前一個的下標是后一個下標的因子
題目分析:讀懂題后不難發(fā)現(xiàn)這是 n * n 最長不下降子序列模板題目的變形題,只是將 n * n 變成了 n log n 而已,轉移方程都沒有變,唯一一個需要證明的就是 1/1 + 1/2 + 1/3 + ... + 1/n = nlogn而已,這個用微積分就能證明,這里就不多說了
代碼:
#include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=1e5+100;int a[N],dp[N];int main() { #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif // ios::sync_with_stdio(false);int w;cin>>w;while(w--){int n;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",a+i);for(int i=1;i<=n;i++)dp[i]=1;int ans=1;for(int i=1;i<=n;i++)for(int j=i+i;j<=n;j+=i)if(a[j]>a[i]){dp[j]=max(dp[j],dp[i]+1);ans=max(ans,dp[j]);}printf("%d\n",ans);}return 0; }?
總結
以上是生活随笔為你收集整理的CodeForces - 1350B Orac and Models(dp)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CodeForces - 1350C O
- 下一篇: CodeForces - 1350E O