openjudge-NOI 2.6-1996 登山

时间:2021-09-19 22:29:16

题目链接:http://noi.openjudge.cn/ch0206/1996/

题解:
  正反求两次LIS即可

 #include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 110
int max,n,a[MAXN],f1[MAXN],f2[MAXN];
int main()
{
scanf("%d",&n);
memset(a,,sizeof(a));
for(int i=;i<=n;i++)f1[i]=f2[i]=;
for(int i=;i<=n;i++)scanf("%d",&a[i]);
int ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<=i-;j++)
if(a[j]<a[i]&&f1[j]>=f1[i])f1[i]=f1[j]+;
}
for(int i=n;i>=;i--)
{
for(int j=n;j>=i+;j--)
if(a[j]<a[i]&&f2[j]>=f2[i])f2[i]=f2[j]+;
}
for(int i=;i<=n;i++)
{
if(f1[i]+f2[i]->ans)ans=f1[i]+f2[i]-;
}
printf("%d\n",ans);
return ;
}