Lweb and String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 261    Accepted Submission(s): 174

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)

 
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.

 
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
 
Author
UESTC
 
Source
 
 
题意:给你一个字符串, 你把它转换成数字,然后求最大递增子序列。
 
大坑, 一直在求最大递增子序列, 一直WA, 最后发现连最大递增子序列也不用求了, 算出字符串中26个小写字母有几个就行了。
 
代码:

#include<stdio.h>
#include<string.h>
#define N 10000006

char s[N];
int a[N];

int main(void)
{
int t, ans, i, j;

scanf("%d", &t);

j = 0;
while(t--)
{
j++;
ans = 0;
memset(a, 0, sizeof(a));
scanf("%s", s);

int n = strlen(s);

for(i = 0; i < n; i++)
a[s[i] - 'a' + 1]++;

for(i = 1; i <= 26; i++)
{
if(a[i])//判断26个英文字母是否出现过, 出现过长度就加1.
ans++;

}

printf("Case #%d: %d\n", j, ans);
}

}

 
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5842 5841 5840 5839 5838 

Lweb and String 超级大水题的更多相关文章

  1. HDU 5842 Lweb and String (水题)

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

  2. hdu 1228 A+B 字符串处理 超级大水题

    中文意思不解释. 很水,我本来想用switch处理字符串,然后编译不通过...原来switch只能处理整数型的啊,我都忘了. 然后就有了很挫的一大串if代码了... 代码: #include < ...

  3. hdu 4548 美素数 超级大水题

    美素数 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submis ...

  4. hdu 1229 超级大水题

      Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Desc ...

  5. HDU 5842 Lweb and String 水题

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

  6. PAT甲题题解-1101. Quick Sort (25)-大水题

    快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...

  7. PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)

    如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...

  8. [BFS,大水题] Codeforces 198B Jumping on Walls

    题目:http://codeforces.com/problemset/problem/198/B Jumping on Walls time limit per test 2 seconds mem ...

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

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

随机推荐

  1. Java多线程的创建(一)

    方法一:继承Thread类实现 1.创建一个类A,并继承Thread类 2.重写A的run()方法 3.创建A的实例对象b,即创建了线程对象 4.使用b调用start()方法:启动线程(会自动调用ru ...

  2. numpy 数组的计算

    一.数组和数的计算 数组和数计算,数组中的每个元素和数进行计算 1.加 import numpy as np arr1 = np.arange(12).reshape(3, 4) print(arr1 ...

  3. elasticsearch为什么比mysql快

    mysql关系型数据库索引原理 数据库的索引是B+tree结构 主键是聚合索引 其他索引是非聚合索引,先从非聚合索引找,见下图 elasticsearch倒排索引原理 两者对比 对于倒排索引,要分两种 ...

  4. 深入浅出MyBatis技术原理与实战

    第1 章 MyBatis 简介..................................................................................... ...

  5. 使用Route Prefix 使用属性路由 精通ASP-NET-MVC-5-弗瑞曼

  6. 使用 CompletableFuture 异步组装数据

    使用 CompletableFuture 异步组装数据 一种快捷.优雅的异步组装数据方式 实际项目中经常遇到这种情况: 从多个表中查找到数据然后拼装成一个VO返回给前端. 这个过程有可能会非常耗时.因 ...

  7. [集训]Trominoes,钩子公式运用

    题意 用这四种骨牌密铺n*m的正方形矩阵,可以不选,求方案数.n*m<=1E8.多组询问. 思考 用如上的表达难以进行计算,尝试转化为一种新的组合解释. 若从右上角开始填起,我们强制要求里面的轮 ...

  8. Eclipse CDT 插件修改自动补全

    eclipse CDT 2019-06代码补全插件 本自动补全文件已在2019-06至2019-09平台上做过测试,均已完美通过功能检测 在原来Eclipse工具补全的基础上新增26个英文字符和&qu ...

  9. 字符串(String)的创建,以及字符串的属性及方法

    1.String对象的创建 方法1: var txt = new String("i am String"); console.log(txt); // 结果为:i am Stri ...

  10. JVM源码分析-JVM源码编译与调试

    要分析JVM的源码,结合资料直接阅读是一种方式,但是遇到一些想不通的场景,必须要结合调试,查看执行路径以及参数具体的值,才能搞得明白.所以我们先来把JVM的源码进行编译,并能够使用GDB进行调试. 编 ...