HDU 5842 Lweb and String (水题)
Lweb and String
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5842
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
Source
2016中国大学生程序设计竞赛 - 网络选拔赛
##题意:
给出一个字符串,确定一组字符到自然数的一一映射.
使得结果数串的严格LIS最大.
##题解:
由于字符串中仅含小写字母,那么结果最大就是26.
所以字符串中有多少个不同的字符,结果就是多少.
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define double long long
#define eps 1e-8
#define maxn 101000
#define mod 1000000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;
char str[maxn];
int main(int argc, char const *argv[])
{
//IN;
int t, ca=1; cin >> t;
while(t--)
{
    scanf("%s", str);
    int ans = 0;
    int sz = strlen(str);
    int state = 0;
    for(int i=0; i<sz; i++) {
        state |= 1<<(str[i]-'a');
    }
    for(int i=0; i<26; i++) {
        if(state & (1<<i)) ans++;
    }
    printf("Case #%d: %d\n", ca++, ans);
}
return 0;
}
HDU 5842 Lweb and String (水题)的更多相关文章
- HDU 5842 Lweb and String 水题
		Lweb and String 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5842 Description Lweb has a string S ... 
- HDU 5842 Lweb and String(Lweb与字符串)
		p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ... 
- HDU 5842 Lweb and String
		Lweb and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ... 
- HDU 5578 Friendship of Frog 水题
		Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ... 
- HDU 5590 ZYB's Biology 水题
		ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ... 
- HDU 5538 L - House Building 水题
		L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ... 
- HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)
		Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ... 
- HDOJ(HDU) 2090 算菜价(简单水题、)
		Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ... 
- HDOJ(HDU)  1555  How many days?(水题)
		Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, ... 
随机推荐
- eclipse jetty插件安装(离线版)
			按照网上的说法安装jetty插件,run-jetty-run,google那个网址根本链接不上.所以插件装不上,网上搜索本地版,试了几个都不好使,功能不全,这是因为下载的本地资源jar包不全导致,好坑 ... 
- 在Ubuntu上为Android系统编写Linux内核驱动程序(老罗学习笔记1)
			这里,我们不会为真实的硬件设备编写内核驱动程序.为了方便描述为Android系统编写内核驱动程序的过程,我们使用一个虚拟的硬件设备,这个设备只有一个4字节的寄存器,它可读可写.想起我们第一次学习程序语 ... 
- BZOJ 2337 XOR和路径(高斯消元)
			题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2337 题意:给定一个带权无向图.从1号点走到n号点.每次从当前点随机(等概率)选择一条相 ... 
- VS2015中的异常配置
			The New Exception Settings Window in Visual Studio 2015Managing Exceptions with the Debugger Underst ... 
- R语言日期时间函数
			Sys.Date( ) returns today's date. date() returns the current date and time.# print today's datetoday ... 
- 1208. Legendary Teams Contest(dfs)
			1208 简单dfs 对于每个数 两种情况 取还是不取 #include <iostream> #include<cstdio> #include<cstring> ... 
- table share
			每个表的表结构会放到table_def_cache中,一个table share对应一个实例 table share 又会实例化为一个对象, 每个进程,每个实例化的对象, 
- UVa 11489 (博弈) Integer Game
			一个数字能被3整除就等价于这个数的各个数字之和被3整除. 所以一开始的时候先要拿一个能使剩下的数字是3的倍数的数. 然后就一直拿0.3.6.9直到某人不能再拿为止. #include <cstd ... 
- UVa 10562 (特殊的输入处理方式) Undraw the Trees
			题意: 给出一个二维字符数组,它代表了一棵树.然后将这棵树转化为括号表示法(以递归的形式). 分析: 这道题最大的特色就是对数据的处理方式,里面用到了一个 fgets() 函数,这个函数的功能有点像c ... 
- JS创建Ajax的XMLHttpRequest对象的通用方法
			function createXMLHttpRequest() { var request = false; if(window.XMLHttpRequest) { request = new XML ... 
