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. IOS网络第一天 - 02SDWebImage

    **************SDWebImage加载图片 #import "HMAppsViewController.h" #import "HMApp.h" ...

  2. js中特有语句-with

    <script type="text/javascript"> /* *为了简化对象调用内容的书写. *可以用js中的特有语句with来完成. *格式 *with{ * ...

  3. NEC学习 ---- 布局 -三列, 左右定宽,中间自适应

    ---恢复内容开始--- 这个布局很牛掰, 我觉得学习价值很大. 通过这个的学习, 我发现, 能将简单的事情做好, 就距离成功不远了. 其实布局就是利用所学知识, 活用. 在没看这个之前, 发现自己的 ...

  4. TCP三次握手四次挥手详解

    转载 http://www.cnblogs.com/zmlctt/p/3690998.html 相对于SOCKET开发者,TCP创建过程和链接折除过程是由TCP/IP协议栈自动创建的.因此开发者并不需 ...

  5. 动画 CABasicAnimation animationWithKeyPath 一些规定的值

    CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...

  6. 白话学习MVC(九)View的呈现一

    一.概述 本节来看一下ASP.NET MVC[View的呈现]的内容,View的呈现是在Action执行之后进行,Action的执行生成一个ActionResult,[View的呈现]的功能就是:通过 ...

  7. github 或者gitlab 设置添加SSH, 避免每次提交重复输入用户名

    克隆项目二种方式: 1. 使用https url克隆,   复制https url 然后到 git clone https-url 2.使用 SSH url 克隆却需要在克隆之前先配置和添加好 SSH ...

  8. oracle deterministic 关键字

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

  9. LUA OOP编程实现方法

    lua原生不支持OOP特性 确实如此, 同时可以采用其它lua代码的方式实现OOP的特性. OOP四大特性 抽象 封装 继承 多态 http://www.cnblogs.com/xiaosongluf ...

  10. APP定制开发:APP软件开发的语言和开发环境

    APP软件开发是移动互联网开发公司常开发的一种手机应用系统,对于刚刚进入APP软件开发领域的新手来说,选择什么编程语言和需要什么开发环境来开发APP软件是常遇到的问题.下面亿合科技小编来为大家分享下: ...