POJ 1887 Testing the CATCHER


子问题:

对于序列1到n

其子问题设为i到n的最大长度

网上很多是从头开始正推,我想的是从尾部开始测试长度分别为1,2,3。。。n的最大长度,原理一样


代码:

#include <iostream>
#include <string>
#include <vector>

struct node
{
	int value;
	int num;
};

int main()
{
	using namespace std;
	int n = 0;
	vector<node> li;
	int count = 0;
	while( true )
	{
		while( 1 )
		{
			cin>>n;
			if( n == -1 )
				break;
			node t ={ n,-1};
			li.push_back(t);
		}
		int len = li.size();
		count ++;
		li[len-1].num = 1;
		int i;
		for( i = len-2; i >= 0; i-- )
		{
			int tvalue = li[i].value;
			int mnum = 0;
			for( int j = i+1; j < len; j++ )
			{
				if( li[j].value <= tvalue && li[j].num >= mnum )
				{
					mnum = li[j].num;
				}
			}
			li[i].num = mnum+1;
		}
		int max = 0;
		for( i = 0; i < len; i++ )
		{
			if( li[i].num > max )
				max = li[i].num;
		}
		li.clear();
		cout<<"Test #"<<count<<":"<<"\n"<<"  "<<"maximum possible interceptions: "<<max<<endl;
		cout<<endl;
		int t2;
		cin>>t2;
		if(t2==-1)
            break;
		node nt ={ t2,-1};
		li.push_back(nt);

	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值