1. 程式人生 > >描述 求一個字串的最長遞增子序列的長度 如:dabdbf最長遞增子序列就是abdf,長度為4 輸入 第一行一個整數0

描述 求一個字串的最長遞增子序列的長度 如:dabdbf最長遞增子序列就是abdf,長度為4 輸入 第一行一個整數0

01.#include<stdio.h> 02.#include<string.h> 03.int main() 04.{ 05.char a[10000]; 06.int count[10000]; 07.int i,j,k,m,len,ch; 08.scanf("%d",&m); 09.while(m--) 10.{ 11.scanf("%s",a); 12.len=strlen(a); 13.k=1; 14.for(i=0;i<len;i++) 15.{ 16.count[i]=1; 17.for(j=0;j<i;j++) 18.{ 19.if(a[i]>a[j]&&count[j]+1>count[i])
20.count[i]=count[j]+1; 21.} 22.if(k<count[i]) 23.k=count[i]; 24.} 25.printf("%d\n",k); 26.}