1 #include<iostream>
2 #include<algorithm>
3 #include<stdlib.h>
4
5 using namespace std;
6
7 int LongestGrowingNumberLength( int* arr,int length,int start)//從start處開始遞增數組的最大長度
8 {
9 if(arr==NULL||length<=0||start<0) return 0;
10 int* begin=arr+start;
11 int* next=begin+1;
12 int count=1;
13 while(next<arr+length)
14 {
15 if(*begin==*next)
16 {
17 next++;
18 begin++;
19 }
20 if(*begin<*next)
21 {
22 *begin=*next;
23 next++;
24 count++;
25 }
26 else next++;
27 }
28 return count;
29 }
30
31 int GrowingNumberLengthCore(int* arr,int length,int start,int end)//最大正序遞增加度
32 {
33 if(arr==NULL||length<0||start<0||end>length-1) return -1;
34 int MaxValue=LongestGrowingNumberLength(arr,length,0);
35 for(int i=1;i<end;i++)
36 {
37 int L=LongestGrowingNumberLength(arr,length,i);
38 if(MaxValue< L)
39 {MaxValue=L;}
40 }
41 return MaxValue;
42 }
43
44 void main()
45 {
46 int n;
47 cin>>n;
48 int* array=new int[n+1];
49 int* resever=new int[n+1];
50 for(int i=0;i<n;i++)
51 {cin>>array[i];}
52 for(i=0;i<n;i++)
53 {resever[i]=array[n-1-i];}
54 int grow=GrowingNumberLengthCore(array,n,0,n-1);//最大正序遞增加度
55 int down=GrowingNumberLengthCore(resever,n,0,n-1);//最大正序遞減長度也就是最大逆序遞增加度
56 cout<<grow<<endl;
57 cout<<down<<endl;
58 cout<<(n+1-grow-down)<<endl;//最少刪除的元素數
59 }