#include <iostream.h>
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void max( int *height, int len ){
int i,j,max[2000],time[2000],max_intercept=0,max_time=0;
for (i=0; i<len; ++i) {max[i]=1;time[i]=0;}
for (i=1; i<len; ++i)
for (j=0; j<i; ++j)
if (height[i]<=height[j] && max[j]+1>max [i])
max[i]=max[j]+1;
for (i=0; i<len; ++i)
if (max[i]>max_intercept) max_intercept=max[i];
cout <<max_intercept<<endl;
}
void need( int *t, int len ){
int *min = new int[len], i=0, need=0, tem=0;
int m1 = 0, m2 =0, tt;
min[0] = 0;
while( i<=len-1 ){
tem = i;
tt = tem;
while( t[tem] >= t[tem+1] ) tem++;
i = 1 + tem;
m2= min[0];
for( int j=0; j<=m1; j++ )
if( m2<= min[j] ) m2 = min[j];
if( t[tt] > m2 )
need++;
min[m1++] = t[tem];
}
cout<< need<<endl;
}
int main(){
int i = 0;
int *t;
char ch;
while( 1 ) {
i = 0;
t = (int *)malloc( sizeof(int) *10 );
cin>>t[i];
if( t[0] == 0 )
exit( 0 );
else{
cin.get( ch );
while( ch !='\n' ){
if( i==9 )
t = (int *)realloc( t, sizeof(int) *( i+11 ) );
cin>> t[++i];
cin.get( ch );
}
max(t,i+1 );
need(t,i+1 );
free(t);
}
}
return 0;
}
正文
stu(3047)2005-08-30 20:24:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/elva6401/4283.html
阅读(2541) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论