码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5256 序列变换

时间:2017-06-30 11:08:25      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:return   include   cin   rac   div   art   ack   using   iostream   

最长上升子序列 nlogn;也是从别人的博客学来的

#include<iostream>
#include<algorithm>
#define maxn 100000+5
using namespace std;
int n;
int a[maxn];
int solve(int b[],int l)
{
	int f[maxn];//f[i]表示子序列长度为i+1的序列中,末尾元素最小的元素的值 
	int k=0;
	f[k++]=b[0];
	for(int i=1;i<l;i++)
	{
		if(b[i]>=f[k-1]) f[k++]=b[i]; 
		else
		{
			int pos=upper_bound(f,f+k,a[i])-f;
			f[pos]=a[i];
		}
	}
	return k;
}
int main()
{
	cin.sync_with_stdio(false);
	int t;
	cin>>t;
	int flag=1;
	while(t--)
	{
		cin>>n;
		for(int i=0;i<n;i++)
		{
			 int x;
			 cin>>x;
			 a[i]=x-i;
		}
		int re=solve(a,n); 
		cout<<"Case "<<"#"<<flag++<<":"<<endl; 
		cout<<n-re<<endl;
	}
	return 0;
}


 

 

hdu 5256 序列变换

标签:return   include   cin   rac   div   art   ack   using   iostream   

原文地址:http://www.cnblogs.com/tlnshuju/p/7097698.html

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