1259:【例9.3】求最长不下降序列
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 const int N=205; 5 int a[N],b[N]; 6 int main(){ 7 int n,t,maxx=0; 8 cin>>n; 9 for(int i=1;i<=n;i++){ 10 scanf("%d",&a[i]); 11 b[i]=1; 12 for(int j=1;j<i;j++) 13 if(a[i]>=a[j]) 14 b[i]=max(b[j]+1,b[i]); 15 if(b[i]>maxx){ 16 maxx=b[i]; 17 t=i; 18 } 19 } 20 printf("max=%d\n",maxx); 21 for(int i=t;i>0;i--){ 22 if(b[i]==maxx&&a[i]<=a[t]){ 23 b[i]=0; 24 maxx--; 25 t=i; 26 } 27 } 28 for(int i=1;i<=n;i++){ 29 if(!b[i])printf("%d ",a[i]); 30 } 31 return 0; 32 }