分析:
一个裸的区间dp,我们只需要注意合并的时候并不像2048那样加倍,每次都加1就好了
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 250; inline int read(){ int f = 1 , x = 0; char ch = getchar(); while(ch > '9' || ch < '0') {if(ch == '-') f = -1; ch = getchar();} while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + ch - '0'; ch = getchar();} return x * f; } int n,m; int f[maxn][maxn],ans; int main(){ n = read(); for(int i=1;i<=n;i++) f[i][i] = read() , ans = max(ans , f[i][i]); for(int i=n;i>=1;i--) for(int j=i+1;j<=n;j++) for(int k=i;k<=j;k++) if(f[i][k] == f[k+1][j]){ f[i][j] = max(f[i][j] , f[i][k] + 1); ans = max(ans , f[i][j]); } printf("%d",ans); return 0; }