zoukankan      html  css  js  c++  java
  • 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);
        }
    
    }
     
  • 相关阅读:
    windows server 2008服务器 做raid0
    SQL Server 2012将数据库备份到网络中的共享文件夹
    SQL Server 2012 使用警报调度数据库作业通知操作员
    Cent OS7上安装并初始化MySQL8.0.15
    nginx 跨域请求、别名路径及防盗链的配置
    ElasticSearch和Kibanna的安装与启动
    Mybatis报错:Result Maps collection already contains value for xx.xxx
    Redis的常见数据类型——String类型
    Redis安装与配置
    nginx日志切割(手动/自动)
  • 原文地址:https://www.cnblogs.com/acmtime/p/5790401.html
Copyright © 2011-2022 走看看