• Lweb and String


    Lweb and String

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 4367    Accepted Submission(s): 1265


    Problem Description
    Lweb has a string S.

    Oneday, he decided to transform this string to a new sequence.

    You need help him determine this transformation to get a sequence which has the longest LIS(Strictly Increasing).

    You need transform every letter in this string to a new number.

    A is the set of letters of S, B is the set of natural numbers.

    Every injection f:AB can be treat as an legal transformation.

    For example, a String “aabc”, A={a,b,c}, and you can transform it to “1 1 2 3”, and the LIS of the new sequence is 3.

    Now help Lweb, find the longest LIS which you can obtain from S.

    LIS: Longest Increasing Subsequence. (https://en.wikipedia.org/wiki/Longest_increasing_subsequence)
     
    Input
    The first line of the input contains the only integer T,(1T20).

    Then T lines follow, the i-th line contains a string S only containing the lowercase letters, the length of S will not exceed 105.
     
    Output
    For each test case, output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer.
     
    Sample Input
    2 aabcc acdeaa
     
    Sample Output
    Case #1: 3 Case #2: 4
     
    这题用了LIS的nlgn的解法,之后竟然是求字母出现的个数。。。
    #include <cstdio>
    #include <vector>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    const int maxn=1e5+5;
    char s[maxn];
    int dp[maxn];
    bool vis[30];
    int main(){
        //freopen("data.in","r",stdin);
        int t,c=0;
        scanf("%d",&t);
        while(t--){
            scanf("%s",s);
            memset(vis,0,sizeof(vis));
            int len=0;
            int n=strlen(s);
            for(int i=0;i<n;i++)
                vis[s[i]-'a'+0]++;
                /*
            dp[1]=s[0];
            for(int i=1;i<n;i++){
                if(s[i]>dp[len])
                    dp[++len]=s[i];
                else {
                    int x= lower_bound(dp,dp+len+1,s[i])-dp;
                    dp[x]=s[i];
                }
            }
            */
            for(int i=0;i<30;i++)
                if(vis[i]) len++;
            printf("Case #%d: %d
    ",++c,len);
        }
    
    }
     
  • 相关阅读:
    子页面向父页面传值
    UEditor的使用方法
    MVC 生成PDf表格并插入图片
    简单行列转换记录
    此数据库没有有效所有者“的解决,我很受用
    ASP.NET MVC3 使用kindeditor编辑器获取不到值
    c#读写文件
    VB 中Sub和Function的区别
    问题集
    hadoop2.7.2运行例子时报错
  • 原文地址:https://www.cnblogs.com/acmtime/p/5790401.html
Copyright © 2020-2023  润新知