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. 动态给drawable上色

    只加载一个资源,然后在运行的时候通过ColorFilter进行上色 public Drawable colorDrawable(Resources res, @DrawableRes int draw ...

  2. 使用safe-rm替代rm

    safe-rm主页: https://launchpad.net/safe-rm 一.下载safe-rm 二.解压文件,拷贝safe-rm到/usr/local/bin/目录下 三.建立软连接: #l ...

  3. AFNetworking 提示"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection" 解决办法

    原因:iOS9以后,苹果把原http协议改成了https协议,所以不能直接在http协议下GET/POST 解决方案之一: 直接编辑工程文件下的Info.plist文件,加入以下代码 <key& ...

  4. XHTML表单

    1.HTML表单标记提供一套元素和属性,用来创建表单,收集网页参观者信息. 2.创建表单结构标记为<form>和</form>. 3.在<form>标记中,我们必须 ...

  5. JS脚本文件的位置对页面加载性能影响以及无阻塞脚本(javascript)模式

    JS的阻塞特性:当<script>出现的时候,页面必须等待脚本文件的加载.解析.执行完毕后才能继续进行页面的渲染.不管脚本文件是以内联形式还是外部引入的形式出现在<script> ...

  6. schtasks在win7下提示错误:无法加载列资源

    转自: http://blog.chinaunix.net/uid-24946452-id-2887851.html 查看cmd 编码 chcp 如使用 936中文GBK编码的话 schtasks.e ...

  7. 简单实用的双向电平转换电路(3.3v-5v)

    当你使用3.3V的单片机的时候,电平转换就在所难免了,经常会遇到3.3转5V或者5V转3.3V的情况,这里介绍一个简单的电路,他可以实现两个电平的相互转换(注意是相互哦,双向的,不是单向的!).电路十 ...

  8. c# 对于批量表的统一查询 WM_CONCAT行列转换行数

    //需要显示的列                sql = string.Format(@"                                      SELECT  WM_ ...

  9. java基础算法-快速排序

    玩博客园很多年,第一次写点什么,就从基础开始吧.最近去面试,发现自己算法忘光了,赶紧复习下.以下代码自带测试类,复制进eclipse中右键 run as -->java application ...

  10. 12月14日《奥威Power-BI销售计划填报》腾讯课堂开课啦

           2016年的最后一个月也过半了,新的一年就要到来,你是否做好了启程的准备?新的一年,有计划,有目标,有方向,才不至于迷茫.规划你的2017,新的一年,遇见更好的自己!        所以 ...