hihocoder 162周 1323 : 回文字符串

hihocoder1323 : 回文字符串(162周)

题目链接

思路:

dp;

ac代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<stdio.h>
#include<map>
#include<cmath>
#include<unordered_map>
#include<unordered_set>

using namespace std;



int main()
{
	string str;
	cin >> str;
	int len = str.length();

	int dp[101][101];
	memset(dp, 0, sizeof(dp));
	int min_oper = len + 1;
	for (int i =  len - 1; i >= 0; i--)
	{
		for (int j = i + 1; j < len; j++)
		{
			if (str[i] == str[j]) dp[i][j] = dp[i + 1][j - 1];
			else
			{
				dp[i][j] = min(dp[i + 1][j], min(dp[i][j - 1], dp[i + 1][j - 1])) + 1;
			}
		}
	}
	printf("%d
", dp[0][len - 1]);


    return 0;
}



原文地址:https://www.cnblogs.com/weedboy/p/7337712.html