#include<stdio.h>
#include<string.h>
char array[10001];
int MaxLen[10001];
//最长递增子序列
void LIS(){
memset(MaxLen,0,sizeof(MaxLen));
int len = strlen(array);
for(int i = 0;i < len;i++){
MaxLen[i] = 1;
for(int j = 0;j < i;j++){
if(array[i] > array[j]){
if(MaxLen[i] < 1 + MaxLen[j]){
MaxLen[i] = 1 + MaxLen[j];
}
}
}
}
}
int main()
{
int N,i,len,Max;
scanf("%d",&N);
//N组测试数据
while(N--){
Max = 0;
scanf("%s",array);
LIS();
len = strlen(array);
//输出最大长度
for(i = 0;i < len;i++){
if(Max < MaxLen[i]){
Max = MaxLen[i];
}
}
printf("%d\n",Max);
}
return 0;
}
最长单调递增子序列
最新推荐文章于 2021-05-10 23:36:46 发布