这题在最长上升子序列的基础上加上了一个限制条件,就是这个上升子序列的原数组下标当前能被前一个整除。
思想还是 dp[i] 表示以 i 结尾的满足条件的最长上升子序列,普通的lst,dp[i]需要从1~ i - 1来得到更新,也可以理解成用1 ~i - 1的dp值来更新dp[i],那么对于这里,只需要枚举满足条件的下标去更新dp[i],即 i 这个下标的因子下标,用埃氏筛的思想。
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
typedef long long ll;
const ll mod = 1e9+7;
int a[man],cnt[man];
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif
int t;
cin >> t;
while(t--){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
cnt[i] = 1;
}
int maxx = 1;
for(int i = 1;i <= n;i++){
for(int j = 2 * i;j <= n;j += i){
if(a[j]>a[i])cnt[j] = max(cnt[j],cnt[i]+1);
}
maxx = max(maxx,cnt[i]);
}
cout << maxx << endl;
}
return 0;
}