CCPC Network race, hdu_5842 Lweb and String

Source: Internet
Author: User

problem DescriptionLweb 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 have 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 \rightarrow b$ can be treat as an legal transformation.

For example, a String "aabc", $A = \{a,b,c \}$, and your 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) InputThe first line of the input contains the only integer $T, (1 \leq T \leq 20) $.

Then $T $ lines follow, the i-th line contains a string $S $ only containing the lowercase letters, the length of $S $ would n OT Exceed $10^5$. OutputFor each of the test case, output A, "case #x: Y", where x was the case number, starting from 1. And y is the answer.

Sample Input2aabccacdeaa Sample OutputCase #1:3Case #2:4The code is as follows:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 6 using namespacestd;7 8 Chars[100010];9 intw[ -];Ten  One intMain () A { -     intT; -     intD =0; the     intsum; -scanf"%d",&t); -      while(t--) -     { +sum =0; -scanf"%s",&s); +Memset (W,0,sizeof(w)); A          for(intI=0; I<strlen (s); i++) at         { -             if(w[s[i]-'a'] ==0){ -sum++; -w[s[i]-'a'] =1; -}Else -             Continue; in         } -printf"Case #%d:%d\n",++d,sum); to     } +     return 0; -}

Thinking Analysis:

The problem is test instructions. A is not out of the sample is confused! Example destroys a lifetime of 2333333, sometimes understanding is really more useful than knocking directly.

CCPC Network race, hdu_5842 Lweb and String

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.