思路:

区间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. Delphi 2007 的重构功能

    Move 移动 1.将选定的静态函数从一个类移动到另一个类 2.将选中的类或接口移动到其他单元 Extract Interface 抽取接口 将选定的函数抽取到一个新的接口中 Extract Supe ...

  2. Unix网络编程 之 socket基础

    基本结构 (这部分的地址均为网络地址<网络字节序>) 1.struct sockaddr:通用套接字地址结构 此结构用于存储通用套接字地址. 数据结构定义: typedef unsigne ...

  3. Android怎样监听蓝牙耳机的按键事件

    Android怎样监听蓝牙耳机的按键事件 写在前面: 直接想要代码非常easy,你直接把滚动栏拉到最底端就能够看到.假设想要十分地了解为什么,那就依照我规划的一步一步来理解.下面測试环境以手头上有的「 ...

  4. 深度学习-theano-windows -cuda-环境搭建

    本文将具体介绍深度学习之cuda的环境搭建 工具:支持CUDA的显卡(安装cuda6.5),VS2013.Anaconda. 步骤: 1.安装cuda6.5 这个不具体介绍,网上有很多文章.注意选择你 ...

  5. 【LeetCode刷题Java版】Reverse Words in a String

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  6. restlet 2.3.5 org.restlet包导入eclipse出现的com.sun.net.httpserver类包找不到问题

    准备过一遍restlet 2.3.5 JavaEE的源码. 环境 eclipse3.7.2 和 jdk 7.0 将org.restlet 包增加到eclipse中.出现 com.sun.net.htt ...

  7. LiveWriter高亮显示方法专题

    2013年9月26日 花了一上午的时间,熟悉了LiveWriter的用法,学会了怎么配置语法高亮,总结下来.   方法1.用博客园推荐的方法没有成功.pass   方法2 方法来自一个人的旅行.试过O ...

  8. 自己定义ViewGroup控件(一)-----&gt;流式布局进阶(一)

    main.xml <? xml version="1.0" encoding="utf-8"?> <com.example.SimpleLay ...

  9. hdu 2665 Kth number(划分树)

    Kth number Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  10. CentOS 6.4安装Ganglia

    samba 1.这里安装的是3.1.7版本,web前端是最新版本,安装前期环境(yum源用的是本地的) yum -y insatll php php-gd rrdtools apr-devel apr ...