思路:

区间dp。

实现:

 class Solution
{
public:
int longestPalindromeSubseq(string s)
{
int n = s.length();
int dp[][];
for (int i = ; i < n; i++)
{
dp[i][i] = ;
if (i != n - ) dp[i][i + ] = (s[i] == s[i + ] ? : );
}
for (int i = n - ; i >= ; i--)
{
for (int j = i + ; j < n; j++)
{
if (s[i] == s[j]) dp[i][j] = dp[i + ][j - ] + ;
else dp[i][j] = max(dp[i + ][j], dp[i][j - ]);
}
}
return dp[][n - ];
}
};

leetcode516 Longest Palindromic Subsequence的更多相关文章

  1. [Swift]LeetCode516. 最长回文子序列 | Longest Palindromic Subsequence

    Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...

  2. [LeetCode] Longest Palindromic Subsequence 最长回文子序列

    Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...

  3. 516. Longest Palindromic Subsequence最长的不连续回文串的长度

    [抄题]: Given a string s, find the longest palindromic subsequence's length in s. You may assume that ...

  4. 516. Longest Palindromic Subsequence

    Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...

  5. [Leetcode] Longest Palindromic Subsequence

    Longest Palindromic Subsequence 题解 题目来源:https://leetcode.com/problems/longest-palindromic-subsequenc ...

  6. LeetCode——Longest Palindromic Subsequence

    1. Question Given a string s, find the longest palindromic subsequence's length in s. You may assume ...

  7. LN : leetcode 516 Longest Palindromic Subsequence

    lc 516 Longest Palindromic Subsequence 516 Longest Palindromic Subsequence Given a string s, find th ...

  8. [LeetCode] 516. Longest Palindromic Subsequence 最长回文子序列

    Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...

  9. LC 516. Longest Palindromic Subsequence

    Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...

随机推荐

  1. 百度UEditor富文本上传图片

    项目中使用UEditor发现设置图片自定义保存路径会出现<请求后台配置项http错误,上传功能将不能正常使用!错误> /* 上传图片配置项 */ "imageActionName ...

  2. Oracle SqlPlus导出查询结果

    Oracle SqlPlus导出查询结果 在sqlplus下导出查询的结果保存到本地sql文件中,可以采用如下方式:1.连接数据库: sqlplus xmq/xmqpwd@192.168.1.57:1 ...

  3. Why we have tuple and list in python

    The most notable difference between tuple and list is that tuple is immutable and list is mutable. B ...

  4. openstack setup demo Image service

    Image service (glance)是openstack中管理vm image的service.本文包含以下内容: overview install overview glance包含以下部分 ...

  5. python操作mysql方法和常见问题

    http://www.cnblogs.com/ma6174/archive/2013/02/21/2920126.html 安装mysql模块 sudo easy_install mysql-pyth ...

  6. Codeforces 479B. Towers 暴力

    纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. yarn-cli 显示文件目录

    显示yarn bin文件夹的位置. yarn bin yarn bin将打印yarn将为您的软件包安装可执行文件的文件夹.一个可执行文件的例子可能是你已经为你的包定义的脚本,可以通过执行yarn ru ...

  8. Postgis经常使用函数

    1,基本操作函数 AddGeometryColumn(<schema_name>, <table_name>,<column_name>, <srid> ...

  9. ionic/cordova 真机调试

    android下简单,连接手机后,直接: myProjectPath>ionic run android ios下比较麻烦点,要先装ios-deploy: ​sudo npm install - ...

  10. 60分钟Python快速学习

    之前和同事谈到Python,每次下班后跑步都是在听他说,例如Python属于“胶水语言啦”,属于“解释型语言啦!”,是“面向对象的语言啦!”,另外没有数据类型,逻辑全靠空格缩进表示等. 今天自己用了6 ...