NYOJ-214 单调递增子序列(二) TLE 分类: NYOJ ...


#include
#include
#define max(x,y)	x>y?x:y
#define MAXX 100005
int num[MAXX] = {0};
int mum[MAXX] = {0};
int sum[2][MAXX] = {0};

int comp ( const void *a, const void *b )
{
    return * ( int * ) a - * ( int * ) b;
}

int main(){
	int n, i, j, k, d;

	while(scanf("%d",&n)!=EOF){
	
		for(i=1;i<=n;i++){
			scanf("%d",&num[i]);
			
			mum[i] = num[i];
			sum[1][i] = sum[0][i] = 0;
		}
	
		qsort(mum, n+1, sizeof(mum[0]), comp);
	
		for(i=1; i<=n; i++){
	
			d = i % 2;
			for(j=1; j<=n; j++){
			
				if(mum[i] == num[j])	sum[d][j] = sum[!d][j-1] + 1;
				else sum[d][j] = max( sum[!d][j], sum[d][j-1]);

			}
		}
	
		printf("%d\n",sum[d][n]);
	}
	return 0;
}

思路来源地:http://qiemengdao.iteye.com/blog/1660229

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/you-well-day-fine/p/4671667.html

你可能感兴趣的:(NYOJ-214 单调递增子序列(二) TLE 分类: NYOJ ...)