Lweb and String HDU - 5842(2016中国大学生程序设计竞赛 - 网络选拔赛)
一水题
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 SS, BB 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 SS.
LIS: Longest Increasing Subsequence. (https://en.wikipedia.org/wiki/Longest_increasing_subsequence)
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 SS, BB 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 SS.
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 SS 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
题意:
咱也不知道这道题什么情况,搞半天是求多少种不同字符
1 #include <stdio.h> 2 #include <string.h> 3 4 int main() 5 { 6 int len, i, t, book[105]; 7 char a[100005]; 8 scanf("%d", &t); 9 int cas = 0, ans; 10 while(t--) 11 { 12 scanf("%s", a); 13 ans = 0; 14 len = strlen(a); 15 memset(book, 0, sizeof(book)); 16 for(i=0; i<len; i++) 17 { 18 if(book[a[i]-'a']==0) 19 { 20 ans++; 21 book[a[i]-'a'] = 1; 22 } 23 } 24 printf("Case %d: %d\n", ++cas, ans); 25 } 26 return 0; 27 }