最长上升字符串

#include 
#include 
#include 

using namespace std;

char a[100050];
char s[100050];

int fi(int l,int r,char s)
{
    int mid;
    while(l<=r)
    {
        mid = (l + r) / 2;
        if(s==a[mid])
            return mid;
        if(s>a[mid])
            l = mid+1;
        else r = mid - 1;
    }
    return l;
}

int dp()
{
    int i,n,len,pos;
    n = strlen(s);
    a[1] = s[0];
    len = 1;
    for(i=1;ia[len])
        {
            len++;
            a[len] = s[i];
        }
        else
        {
            pos = fi(0,len,s[i]);
            a[pos] = s[i];
        }
    }
    return len;
}

int main()
{
    int t,k = 1,m;
    scanf("%d",&t);

    while(t--)
    {
        scanf("%s",s);
        m = dp();
        printf("Case #%d: %d\n",k++,m);
    }
    return 0;
}

 

你可能感兴趣的:(VJ)