洛谷P3147 DP-倍增
题目链接:https://www.luogu.com.cn/problem/P3147
题目大意:
#include<bits/stdc++.h> #define LL long long using namespace std; int f[60][300000]; int main(){ int n, x; scanf("%d",&n); for(int i=1; i<=n; i++){ scanf("%d", &x); f[x][i]=i+1; } int ans=0; for(int i=2; i<=58; i++){ for(int k=1; k<=n; k++){ f[i][k]=max(f[i][k], f[i-1][f[i-1][k]]); if(f[i][k]){ ans=i; } } } cout<<ans<<endl; return 0; }