Lweb and String HDU - 5842

题目传送~~~

又是一个最长上升子序列的题。。。

但又和最长上升子序列没有任何关系。。。

分析一下:水题无疑只要你不执著于觉得分要用最长上升子序列刷刷,就可以看出。他的abcd.....等字母的值是由你转换的。还有折磨好的事情,没错你想他是啥就是啥。。。。

那这就出来了他的LIS是多少呢,在我们不傻的情况下,我们肯定会尽量指定数让他为上升子序列。所以我们只需要数字母个数就阔以了。

附上代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<vector>
using namespace std;
int t;
const int maxn = 100010;
char ch[maxn],ah[maxn];
int c = 0;
int main()
{
	scanf("%d", &t);
	while (t--)
	{
		c++;
		scanf("%s", ch);
		printf("Case #%d: ", c);
		int len = strlen(ch);
		int a = 0,flag = 0;
		for (int i = 0; i < len; i++)
		{
			for (int j = 0; j < a; j++)
			{
				if (ch[i] == ah[j])
				{
					flag = 1;
					break;
				}
			}
			if (!flag)
			{
				ah[a++] = ch[i];
			}
			flag = 0;
		}
		printf("%d\n", a);
	}

	return 0;
}
//printf("Case #%d: ", c);
		

猜你喜欢

转载自blog.csdn.net/fighting_yifeng/article/details/81673104