#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
int dp[5050][5050],a[5050];
int n,ans;
int read()
{
char ch=getchar();int ret=0;
for (;!isdigit(ch);ch=getchar());
for (;isdigit(ch);ch=getchar())ret=ret*10+ch-'0';
return ret;
}
int main()
{
n=read();
for (int i=0;i<n;i++) a[i]=read();
for (int i=n-1;i>=1;i--) a[i]=a[i]-a[i-1];
for (int i=1;i<n;i++)
{
for (int j=i+ans+1;j<n;j++)
if (a[i]==a[j])
{
dp[i][j]=min(j-i-1,dp[i-1][j-1]+1);
ans=max(ans,dp[i][j]);
}
}
printf("%d\n",ans>3?ans+1:0);
return 0;
}
【USACO5-1-3】乐曲主题Musical Themes dp
最新推荐文章于 2019-05-22 17:50:00 发布