RT,为什么本地运行过了,提交上去却CE了。
code
#include<bits/stdc++.h>
using namespace std;
int n, ans, a[262145], f[262145][262145], l;
int dfs(int l, int r){
if(f[l][r] != -1)
return f[l][r];
if(l == r)
return f[l][r] = a[l];
int t = 0;
for(int i = l; i < r; ++i){
int n1 = dfs(l, i), n2 = dfs(i + 1, r);
if(n1 && n2 && n1 == n2)
t = max(t, n1 + 1);
}
return f[l][r] = t;
}
int main(){
cin >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
f[i][j] = -1;
for(int i = 1; i <= n; ++i)
cin >> a[i];
l = dfs(1, n);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
ans = max(f[i][j], ans);
cout << ans;
return 0;
}