代码
#include <iostream>
using namespace std;
void Lis_inc_dec_max(int a[],int n)
{
int i,j;
int *f1 = new int [n];
int *f2 = new int [n];
for (i = 0;i < n;i++)
{
f1[i] = 1;
for (j = 0;j < i ;j++)
if (a[j] < a[i])
f1[i] = max(f1[i],f1[j]+1);
}
for (i = n-1;i >= 0;i--)
{
f2[i] = 1;
for (j = n-1;j > i ;j--)
if (a[i] > a[j])
f2[i] = max(f2[i],f2[j]+1);
}
for (i = 0;i < n;i++)
cout << f1[i] << " ";
cout << endl;
for (i = 0;i < n;i++)
cout << f2[i] << " ";
cout << endl;
int max = -99999;
for (i = 0;i < n;i++)
{
if (max < f1[i]+f2[i]-1)
max = f1[i]+f2[i]-1;
}
cout << max << endl;
}
int main()
{
int a[]={186,186,150,200,160,130,197,220};
Lis_inc_dec_max(a,8);
return 0;
}