日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

CodeForces - 1350B Orac and Models(dp)

發(fā)布時(shí)間:2024/4/11 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces - 1350B Orac and Models(dp) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目鏈接:點(diǎn)擊查看

題目大意:給出一個(gè)長(zhǎng)度為 n 的數(shù)列,求出最長(zhǎng)上升子序列的長(zhǎng)度,滿足前一個(gè)的下標(biāo)是后一個(gè)下標(biāo)的因子

題目分析:讀懂題后不難發(fā)現(xiàn)這是 n * n 最長(zhǎng)不下降子序列模板題目的變形題,只是將 n * n 變成了 n log n 而已,轉(zhuǎn)移方程都沒(méi)有變,唯一一個(gè)需要證明的就是 1/1 + 1/2 + 1/3 + ... + 1/n = nlogn而已,這個(gè)用微積分就能證明,這里就不多說(shuō)了

代碼:

#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; }

?

總結(jié)

以上是生活随笔為你收集整理的CodeForces - 1350B Orac and Models(dp)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。