码迷,mamicode.com
首页 > 编程语言 > 详细

poj1631——树状数组求LIS

时间:2018-02-28 22:58:54      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:update   amp   date   max   target   iostream   AC   query   set   

题目:http://poj.org/problem?id=1631

求LIS即可,我使用了树状数组。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,p,a[40005],f[40005];
int query(int x)
{
	int ret=0;
	for(;x;x-=x&-x)
		ret=max(ret,f[x]);
	return ret;
}
void update(int x,int k)
{
	for(;x<=p;x+=x&-x)
		f[x]=max(f[x],k);
}
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&p);
		memset(f,0,sizeof f);
		for(int i=1;i<=p;i++)
		{
			scanf("%d",&a[i]);
			int k=query(a[i]);
			update(a[i],k+1);
		}
		printf("%d\n",query(p));
	}
	return 0;
}

  

poj1631——树状数组求LIS

标签:update   amp   date   max   target   iostream   AC   query   set   

原文地址:https://www.cnblogs.com/Zinn/p/8485817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!