NYOJ17——单调递增最长子序列

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=17

题目分析:这是基本题,没什么好分析的。只有把基础算法烂熟于心,才能更好的应付那些算法的变种。

相关题目链接:http://blog.csdn.net/kay_zhyu/article/details/8714581

http://blog.csdn.net/kay_zhyu/article/details/8713068

#include<stdio.h>
#include<string.h>

char str[10000];
int dp[10000];

int max(const int a, const int b)
{
	return a > b ? a : b;
}

int DP(int n)
{
	int i,j;
	dp[0] = 1;
	int ans = 1;
	for(i = 1; i < n; ++i)
	{
		dp[i] = 1;
		for(j = 0; j < i; ++j)
		{
			if(str[j] < str[i])
				dp[i] = max(dp[i],dp[j] + 1);
		}
		ans = max(ans,dp[i]);
	}
	return ans;
}

int main()
{
	int t,nLen;
	int i,k;
	int ans;
	scanf("%d",&t);
	getchar();
	while(t--)
	{
		gets(str);
		nLen = strlen(str);
		ans = DP(nLen);
		printf("%d\n",ans);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值