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. C# 常用类

    一.Convert 主要用于数据类型的转换,常用的静态方法有: Convert.ToSingle():把数据转换为单精度浮点数,参数常为字符串 Convert.ToDouble():转为双精度浮点数 ...

  2. Color Space: Ycc

    在进行图像扫描时,有一种重要的扫描输入设备PhotoCd,由于PhotoCd在存储图像的时候要经过一种模式压缩,所以PhotoCd采用了Ycc颜色空间,此空间将亮度作由它的主要组件,具有两个单独的颜色 ...

  3. 导入TDP数据包备份

    package org.alfresco.repo.bom.util; import java.io.BufferedReader; import java.io.File; import java. ...

  4. c语言中的指针问题

    “*”符号的作用在C语言中有两种: 1.声明该变量是指针,例如:int * p;//表示声明一个int类型的指针,变量名为p 2.在指针运算时,表示取这个地址上的内容,例如  temp = *p;// ...

  5. DreamweaverCS6

    1.设置文字的格式:<font face=""></font>  字号<font size=""> 颜色<font c ...

  6. JAVASE02-Unit01: API文档 、 字符串基本操作

    API文档 . 字符串基本操作 文档注释 package day01; /** * 文档注释只能定义在三个地方: * 类,方法,常量 * * 文档注释是功能注释,用来说明功能作用 * 在类上使用的目的 ...

  7. 物理主机win 7系统迁移至VMware ESXI服务器

    一.实验环境如下图所示: 二.实验要求(如上图所示) 通过 计算机B  (IP:10.8.9.18) 将 计算机A (IP:10.8.9.155) 迁移到 服务器(IP:10.8.9.161) 三.实 ...

  8. delphi之动态库调用和串口通讯

    串口通讯: Spcomm 控件属性: CommName  :表示COM1,COM2等串口的名字: BaudRate:设定波特率9600,4800等 StartComm StopComm 函数Write ...

  9. oracle deterministic 关键字

    多次看到DETERMINISTIC,一直很疑惑,今天做了一个实验.我们欺骗Oracle说是一个DETERMINISTIC函数,它在SQL中只调用一次.如果不使用DETERMINISTIC,可以看到出来 ...

  10. on-my-zsh agnoster 主题设置问题

    安装Menlo-Powerline字体补丁 https://gist.github.com/qrush/1595572/raw/417a3fa36e35ca91d6d23ac96107... 然后 c ...