首页 > 其他 > 详细

腾讯笔试题---最长回文字符串

时间:2016-04-09 23:34:04      阅读:305      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 10001;
char s1[maxn], s2[maxn];
int dp[maxn][maxn];

int count(char* s1, char* s2)
{
	int len1 = strlen(s1);
	int len2 = strlen(s2);
	for (int i = 0; i < len1 + 2; i++)
	{
		for (int j = 0; j < len2 + 2; j++)
		{
			dp[i][j] = 0;
		}
	}
	for (int i = 1; i <= len1; i++)
	{
		for (int j = 1; j <= len2; j++)
		{
			if (s1[i - 1] == s2[j - 1])
			{
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	return dp[len1][len2];
}
/*
int main()
{
	char s1[maxn];
	char s2[maxn];
	cin >> s1;
	int len = strlen(s1);
	for (int i = 0; i < len;i++)
	{
		s2[i] = s1[len-1-i];
	}
	s2[len] = s1[len];
	cout << count(s1, s2) << endl;
}
*/

  

腾讯笔试题---最长回文字符串

原文:http://www.cnblogs.com/jinweiseu/p/5372970.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!