一道经典的最长上升子序列。
用的是二分法 我看大牛们的模板全是在手写二分。表示对二分的掌控能力还是有些差劲,所以调用了函数。
代码如下:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int M=10005;
char b[M];
char s[M];
int l;
int lis()
{
//b[0]=1;
b[0]=s[0];
int cur=1;
for(int i=0; i<l; i++)
{
int j=lower_bound(b,b+cur,s[i])-b;
b[j]=s[i];
if(j>=cur)
cur++;
}
return cur;
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
getchar();
while(t--)
{
gets(s);
//puts(s);
l=strlen(s);
printf("%d\n",lis());
}
return 0;
}