标签:
6
100 154 167 159 132 105
5
152 152 152 152 152
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 }
标签:
原文地址:http://www.cnblogs.com/wxdjss/p/5697400.html