Lweb and String

Lweb and String

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

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

这题用了LIS的nlgn的解法,之后竟然是求字母出现的个数。。。

#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
char s[maxn];
int dp[maxn];
bool vis[30];
int main(){
    //freopen("data.in","r",stdin);
    int t,c=0;
    scanf("%d",&t);
    while(t--){
        scanf("%s",s);
        memset(vis,0,sizeof(vis));
        int len=0;
        int n=strlen(s);
        for(int i=0;i<n;i++)
            vis[s[i]-‘a‘+0]++;
            /*
        dp[1]=s[0];
        for(int i=1;i<n;i++){
            if(s[i]>dp[len])
                dp[++len]=s[i];
            else {
                int x= lower_bound(dp,dp+len+1,s[i])-dp;
                dp[x]=s[i];
            }
        }
        */
        for(int i=0;i<30;i++)
            if(vis[i]) len++;
        printf("Case #%d: %d\n",++c,len);
    }

}
时间: 2024-11-06 07:30:05

Lweb and String的相关文章

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

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

HDU 5842 Lweb and String

Lweb and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 368    Accepted Submission(s): 243 Problem Description Lweb has a string S. Oneday, he decided to transform this string to a new s

HDU5842 Lweb and String【水题】

Lweb and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2062 Accepted Submission(s): 956 Problem Description Lweb has a string S. Oneday, he decided to transform this string to a new seque

CCPC网络赛,HDU_5842 Lweb and String

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 lette

HDU 5842 Lweb and String (水题)

题意:给定一个字符串,问你有多少种字母. 析:用set即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #incl

2016中国大学生程序设计竞赛 - 网络选拔赛 1011 Lweb and String

题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=719 Sample Input 2 aabcc acdeaa Sample Output Case #1: 3 Case #2: 4 *************************************************** 题意:我只能说题意神马都是浮云,纯属干扰,直接看代码吧 1 #include<stdio.h> 2 #i

【STL】【HDU5842】2016中国大学生程序设计竞赛 - 网络选拔赛 K. Lweb and String (set)(水~~~)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5842 水题,可以用来练习STL中的set 题目大意:给你一串字符串,字符串中的某个字母可以替换为一个数字,求最长上升子序列 例如: aabcdef --> 1123456 acdeaa  --> 123411    aabcc    --> 11233    dacbdda--> 1234112 红色字体为最长上升子序列 所以我们只需要统计有多少种不同的字母便可以得到答案 代码:(set解

[CCPC]网赛部分比赛代码

来自HDOJ: 5833 ( Zhu and 772002 ) 1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostre

2016 CCPC 网络赛 B 高斯消元 C 树形dp(待补) G 状压dp+容斥(待补) H 计算几何

2016 CCPC 网络赛 A - A water problem 水题,但读题有个坑,输入数字长度很大.. B - Zhu and 772002 题意:给出n个数(给出的每个数的质因子最大不超过2000),选出多个数相乘得b.问有多少种选法让b 为完全平方数. tags:高斯消元,求异或方程组解的个数.   好题 每个数先素数分解开.  对于2000以内的每个素数p[i],这n个数有奇数个p[i]则系数为1,偶数个则系数为0,最后n个数的p[i]系数异或和都要为0才会使得最后的积为完全平方数.