zoukankan      html  css  js  c++  java
  • 最大回文子串长度 [dp]

    dp 将复杂度降到n平方
    在这里插入图片描述

    #include<iostream>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<string>
    #include<math.h>
    #include<algorithm>
    #include<map>
    #include<cstring>
    #include<set>
    using namespace std;
    bool dp[100][100];
    int main()
    {
    	string s;
    	cin >> s;
    	int maxn = s.size();
    	for (int i = 0; i < maxn; i++)
    	{
    		dp[i][i] = true;
    	}
    	int max = 1;
    	for (int j = 1; j < maxn; j++)
    	{
    		for (int i = 0; i < maxn - 1&&i<j; i++)
    		{
    			if (s[i] != s[j])
    			{
    				dp[i][j] = false;
    			}
    			else
    			{
    				if (j - i < 3)
    				{
    					dp[i][j] = true;
    				}
    				else
    				{
    					dp[i][j] = dp[i + 1][j - 1];
    				}
    			}
    			if (dp[i][j] && j - i + 1 > max)
    			{
    				max = j - i + 1;
    			}
    		}
    	}
    	cout << max << endl;
    }
    
    
  • 相关阅读:
    Domino
    tomcat 部署 外网访问
    市场4
    android 源码下载编译
    SSIS
    代码审查工具
    mfc 常用控件
    屏蔽home
    MFC BEGIN_MESSAGE_MAP()
    社交产品
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13811987.html
Copyright © 2011-2022 走看看