標籤:printf 字元 decided time str rom orm family tar
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},你可以轉換成“1 1 2 3”,新串的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
10
5.
輸入的第一行只有一個整數T,(1≤T≤20)。隨後T行,每行都有一個僅由小寫字母組成的字串S,S的長度不超過10^5。
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 - 輸入範例
2aabccacdeaa
Sample Output - 輸出範例
Case #1: 3Case #2: 4
題解
字母轉數字,然後求最長升序子序列的長度。
因此映射關係是隨意自定的,因此題目只要求字串中的字母種類數量即可。
代碼 C++
1 #include <cstdio> 2 #include <cstring> 3 char data[100005], inUS[128]; 4 int main(){ 5 int t, i, j, opt; 6 scanf("%d ", &t); 7 for (i = 1; i <= t; ++i){ 8 gets(data); 9 memset(inUS, 0, sizeof(inUS)); opt = 0;10 for (j = 0; data[j]; ++j){11 if (~inUS[data[j]]) ++opt, --inUS[data[j]];12 }13 printf("Case #%d: %d\n", i, opt);14 }15 return 0;16 }
HDU 5842 Lweb and String(Lweb與字串)