题目链接:http://noi.openjudge.cn/ch0206/1996/
题解:
正反求两次LIS即可
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 #define MAXN 110 5 int max,n,a[MAXN],f1[MAXN],f2[MAXN]; 6 int main() 7 { 8 scanf("%d",&n); 9 memset(a,0,sizeof(a)); 10 for(int i=1;i<=n;i++)f1[i]=f2[i]=1; 11 for(int i=1;i<=n;i++)scanf("%d",&a[i]); 12 int ans=0; 13 for(int i=1;i<=n;i++) 14 { 15 for(int j=1;j<=i-1;j++) 16 if(a[j]<a[i]&&f1[j]>=f1[i])f1[i]=f1[j]+1; 17 } 18 for(int i=n;i>=1;i--) 19 { 20 for(int j=n;j>=i+1;j--) 21 if(a[j]<a[i]&&f2[j]>=f2[i])f2[i]=f2[j]+1; 22 } 23 for(int i=1;i<=n;i++) 24 { 25 if(f1[i]+f2[i]-1>ans)ans=f1[i]+f2[i]-1; 26 } 27 printf("%d ",ans); 28 return 0; 29 }