hdu_5748_Bellovin(LIS)

题目链接:hdu_5748_Bellovin

题意:

给你一个数列ai,设f(a1,a2,a3,..an)=(f1,f2,f3,...,fn),其中fi表示以ai结尾的最长递增子序列长度,注意:必须要包括ai,当时就是被这里坑了,这TM也太坑爹了

题解:

直接上nlogn的LIS算法,记录一下位置就行了

 1 #include<map>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<queue>
 5 #include<vector>
 6 #include<string>
 7 #include<cstring>
 8 #include<algorithm>
 9 #include<functional>
10 #define pb push_back
11 #define ls l,m,rt<<1
12 #define rs m+1,r,rt<<1|1
13 #define mst(a,b) memset(a,b,sizeof(a))
14 #define F(i,a,b) for(int i=a;i<=b;++i)
15 #define ___ freopen("c:\\acm\\input.txt","r",stdin);
16 using namespace std;
17 typedef long long LL;
18 
19 int n,a[100010],ans[100010];
20 
21 int main(){
22     int t;
23     scanf("%d",&t);
24     while(t--)
25     {
26         int len=1,tp;
27         scanf("%d%d",&n,&tp);
28         a[1]=tp,ans[1]=1;
29         F(i,2,n)
30         {
31             scanf("%d",&tp);
32             if(a[len]<tp)a[++len]=tp,ans[i]=len;
33             else {
34                 int pos=lower_bound(a+1,a+1+len,tp)-a;
35                 a[pos]=tp,ans[i]=pos;
36             }
37         }
38         F(i,1,n)printf("%d%c",ans[i],i==n?'\n':' ');
39     }
40     return 0;
41 }
View Code

 

转载于:https://www.cnblogs.com/bin-gege/p/5699612.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值