zoukankan      html  css  js  c++  java
  • HDU 5842 Lweb and String 【乱搞】

    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 SB 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最大

    大致思路:

    一开始没看到随便映射,直接套一个LIS的模板,发现复杂度不可能。所以又重新读了一遍题。

    既然是随便映射,并且不同字母映射的值肯定是不一样的。那么让求可能的最大值,其实就是数有多少个不同的字母。

    把字母个数输出就好了。

    代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 set<char> st;
     4 int main()
     5 {
     6     ios::sync_with_stdio(false);
     7     int t,cnt=1,ans;
     8     string str;
     9     cin>>t;
    10     for(;cnt<=t;++cnt){
    11         st.clear();
    12         ans=0;
    13         cin>>str;
    14         for(int i=0;i<str.size();++i)
    15             st.insert(str[i]);
    16         ans=st.size();
    17         cout<<"Case #"<<cnt<<": "<<ans<<endl;;
    18     }
    19     return 0;
    20 }

     

  • 相关阅读:
    powerdesigner
    UML类图几种关系的总结(转载 http://blog.csdn.net/tianhai110/article/details/6339565 )
    vuex
    options请求(复杂请求)
    Vue 编程式的导航
    JS定义类
    cors中间件
    vue axios
    restframewor 版本(version)
    pycharm 安装vue
  • 原文地址:https://www.cnblogs.com/SCaryon/p/7390582.html
Copyright © 2011-2022 走看看