码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-04-09 23:36:03      阅读:169      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!