HDU 5842 Lweb and String(Lweb与字符串)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

 

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:A→B 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)
Lweb有个字符串S

某天,他决定用原串弄腾出一个新串。

你需要帮他确定变化的形式,使得新串具有最长的LIS(严格递增)。

你需要把字符串中的每种字母转化成一个数字。

A是S的字母集合,B是自然数集合。

任意映射 f:A→B 都是合法变动。

比如说,一个字符串“aabc”,A={a,b,c},你可以转换成“   ”,新串的LIS长度为3。

现在帮帮Lweb找出你能从S中获得的最长LIS。

LIS:最长升序子序列。(https://en.wikipedia.org/wiki/Longest_increasing_subsequence)

CN

Input - 输入
The first line of the input contains the only integer T,(1≤T≤20)
 
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.
输入的第一行只有一个整数T,(≤T≤)。

随后T行,每行都有一个仅由小写字母组成的字符串S,S的长度不超过10^。

CN

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.
对于每组测试用例,输出一行"Case #x: y",x表示测试用例的编号,从1开始。y为答案。

CN

Sample Input - 输入样例

2
aabcc
acdeaa

Sample Output - 输出样例

Case #1: 3
Case #2: 4

题解

  字母转数字,然后求最长升序子序列的长度。

  因此映射关系是随意自定的,因此题目只要求字符串中的字母种类数量即可。

代码 C++

 #include <cstdio>
#include <cstring>
char data[], inUS[];
int main(){
int t, i, j, opt;
scanf("%d ", &t);
for (i = ; i <= t; ++i){
gets(data);
memset(inUS, , sizeof(inUS)); opt = ;
for (j = ; data[j]; ++j){
if (~inUS[data[j]]) ++opt, --inUS[data[j]];
}
printf("Case #%d: %d\n", i, opt);
}
return ;
}

HDU 5842 Lweb and String(Lweb与字符串)的更多相关文章

  1. HDU 3336 Count the string 查找匹配字符串

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 5842 Lweb and String (水题)

    Lweb and String 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5842 Description Lweb has a string S ...

  3. HDU 5842 Lweb and String 水题

    Lweb and String 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5842 Description Lweb has a string S ...

  4. HDU 5842 Lweb and String

    Lweb and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. Lweb and String 超级大水题

    Lweb and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. HDU 3973 AC's String 字符串哈希

    HDU 3973 通过哈希函数将一个字符串转化为一个整数,通过特定的方式可以使得这个哈希值几乎没有冲突(这就是关键之处,几乎没有视为没有= =!, 其实也可以考虑实现哈希冲突时的处理,只是这道题没必要 ...

  7. hdu 4850 Wow! Such String! 欧拉回路

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4080264.html 题目链接:hdu 4850 Wow! Such String! 欧拉回 ...

  8. hdu 3553 Just a String (后缀数组)

    hdu 3553 Just a String (后缀数组) 题意:很简单,问一个字符串的第k大的子串是谁. 解题思路:后缀数组.先预处理一遍,把能算的都算出来.将后缀按sa排序,假如我们知道答案在那个 ...

  9. HDU 4850 Wow! Such String!(欧拉道路)

    HDU 4850 Wow! Such String! 题目链接 题意:求50W内的字符串.要求长度大于等于4的子串,仅仅出现一次 思路:须要推理.考虑4个字母的字符串,一共同拥有26^4种,这些由这些 ...

随机推荐

  1. Unity3D 开发 之 JDK安装与环境变量配置

     安装JDK 选择安装目录 安装过程中会出现两次 安装提示 .第一次是安装 jdk ,第二次是安装 jre .建议两个都安装在同一个java文件夹中的不同文件夹中.(不能都安装在java文件夹的根目录 ...

  2. Tomcat性能调优

    1.集成apache 虽然Tomcat也可以作web服务器,但是处理静态html的速度比不上apache,且其作为web服务器的功能远不如Apache,因此把apache和tomcat集成起来,讲ht ...

  3. mysql中profile的使用

    1.profile在mysql5.0.37及其以上版本中可用 2.查看profile是否可用SELECT @@profiling;来查看是否已经启用profile,如果profilng值为0,可以通过 ...

  4. C使用相关笔记

    #将c文件编译成动态库 //hello.c int hello_add(int a, int b) { return a + b; } gcc -O -c -fPIC -o hello.o hello ...

  5. react-native 问题总结

    给npm换源 1.通过config配置指向国内源 npm config set registry http://registry.cnpmjs.org //配置指向源 npm info express ...

  6. HDFS的概念

    1.数据块 每个磁盘都有默认的数据块大小,这是磁盘进行数据读/写的最小单位.构建于单个磁盘之上的文件系统通过磁盘块来管理该文件系统中的块,该文件系统块的大小可以是磁盘块的整数倍.文件系统快一半为几千字 ...

  7. 《Linux内核分析》第七周 可执行程序的装载

    [刘蔚然 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000] WEEK SEVEN ...

  8. sublimetext ruby 插件

    写ruby的编辑器推荐  俗话说磨刀不误砍柴工,好的编辑器可以写的更舒服,更快. 完全初学者建议用RubyMine,这个目前估计最强的写Ruby的IDE. 不过我没有使用它,因为它速度太慢了.如果你能 ...

  9. TCP/IP协议 三次握手与四次挥手

    一.TCP报文格式 TCP/IP协议的详细信息参看<TCP/IP协议详解>三卷本.下面是TCP报文格式图: 图1 TCP报文格式 上图中有几个字段需要重点介绍下:        (1)序号 ...

  10. sql操作之修改表结构

    修改表的语法=========================增加列[add 列名]=========================①alter table 表名 add 列名 列类型 列参数[加的 ...