题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5842
题目大意:给出一个由小写字母组成的字符串,要求求出它的最大上升子序列
解题思路:这道题考验的是读题能力……………………虽然表面上要求的是最大上升子序列,但如果真的去求最大上升子序列的话一定会T或者WA,因为题目中给了一个条件,就是字母和数字之间存在一个映射关系,意味着一个字母可以被映射成为任意数字,这样一来,只要字母不一样,则一定可以映射成递增的数字,因此题目转换成了求字符串中不同字母的个数………………坑爹啊,一直在求最大上升子序列,贡献了16次T和WA,哎,都是泪。
AC代码:
#include<cstdio> #include<cstring> #include<map> #include <set> #include <iostream> #define MAXN 100005 using namespace std; int arr[MAXN],ans[MAXN],len; int main() { int t; int index=0; //cin>>t; scanf("%d",&t); for(int tt=1;tt<=t;tt++) { index=0; char a[100005]; char b[100005]; scanf("%s",a); for(int i=0;i<strlen(a);i++) { int j; for(j=0;j<index;j++) { if(b[j]==a[i])break; } if(j==index)b[index++] = a[i]; } printf("Case #%d: %d\n",tt,index); } return 0; }