您的位置:首页 > 其它

poj 1887 Testing the CATCHER 最长不升子序列

2011-10-05 17:06 399 查看
题目链接:http://poj.org/problem?id=1887

题目大意:求给定数列到最长不升子序列。关键注意到结果输出完毕后至少要输出1行空行。

代码如下:

#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>

const int maxx = 100001;
int num[maxx],dp[maxx];

void max(int &a,int b){
	if(a<b)a = b;
}

int main(){

	int pos = 0,nu,i,j,cas=0;

	while(scanf("%d",&nu)){
		if(nu!=-1){
			dp[pos] = 1;
			num[pos++] = nu;
			continue;
		}
		if(nu==-1 && pos==0){
			break;
		}

		++cas;

		for(i=0;i<pos;++i){
			for(j=0;j<i;++j){
				if(num[i]<=num[j]){
					max(dp[i],dp[j]+1);
				}
			}
		}

		int maxx = -1;
		for(i=0;i<pos;++i)if(dp[i]>maxx)maxx = dp[i];
		printf("Test #%d:\n",cas);
		printf("  maximum possible interceptions: %d\n\n",maxx);
		pos = 0;
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: