leetcode516 Longest Palindromic Subsequence
思路:
区间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的更多相关文章
- [Swift]LeetCode516. 最长回文子序列 | Longest Palindromic Subsequence
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...
- [LeetCode] Longest Palindromic Subsequence 最长回文子序列
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...
- 516. Longest Palindromic Subsequence最长的不连续回文串的长度
[抄题]: Given a string s, find the longest palindromic subsequence's length in s. You may assume that ...
- 516. Longest Palindromic Subsequence
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...
- [Leetcode] Longest Palindromic Subsequence
Longest Palindromic Subsequence 题解 题目来源:https://leetcode.com/problems/longest-palindromic-subsequenc ...
- LeetCode——Longest Palindromic Subsequence
1. Question Given a string s, find the longest palindromic subsequence's length in s. You may assume ...
- LN : leetcode 516 Longest Palindromic Subsequence
lc 516 Longest Palindromic Subsequence 516 Longest Palindromic Subsequence Given a string s, find th ...
- [LeetCode] 516. Longest Palindromic Subsequence 最长回文子序列
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...
- LC 516. Longest Palindromic Subsequence
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...
随机推荐
- nodejs window下安装与配置淘宝镜像
1,前往nodejs官网下载安装软件,地址:https://nodejs.org/en/ 2,点击下一步继续安装,安装完成,在命令输入:node -v,npm -v,查看版本,即是安装成功 3,随便在 ...
- laravel event
事件监听 方法一: web.php Event::listen('eloquent.created: App\post',function(){ dump('A post was created'); ...
- canvas 插件
http://www.jq22.com/yanshi2217 参考这个站 发现一些比较有用的canvas插件: 线形图插件:jquery.sparkline 2.1.1 excanvas 环形图,饼状 ...
- import与require的区别
载入一个模块import() 与 require() 功能相同,但具有一定程度的自动化特性.假设我们有如下的目录结构:~~~app/app/classes/app/classes/MyClass.lu ...
- X-pack-6.2.4破解
1.前言: X-pack是elasticsearch的一个扩展包,将安全,警告,监视,图形和报告功能捆绑在一个易于安装的软件包中,虽然x-pack被设计为一个无缝的工作,但是你可以轻松的启用或者关闭一 ...
- 《编程导论(Java)·3.1.2 方法》之 副作用
4. 副作用 在一些语言如Pascal中,子程序被分成两种:函数和过程.尽管Java没有强制性地要求将方法区分为命令和函数.然而这样的差别对于良好地设计程序有非常大的帮助[1]. 首先说明一个概念:副 ...
- 用R进行微博分析的初步尝试
新浪微博如火如荼,基于微博的各种应用也层出不穷. 有一种共识似乎是:微博数据蕴含着丰富的信息,加以适当的挖掘.可以实现众多商业应用.恰好社会网络分析也是我之前有所了解并持续学习的一个领域,因此我做了微 ...
- MongoDb 学习教程
MongoDB教程首页 MongoDB 介绍 MongoDB 优点 MongoDB 安装(Window/Linux) MongoDB 数据模型 MongoDB 创建数据库 MongoDB 删除数据库 ...
- linux c 获取当前执行进程总数
获取当前执行进程总数的命令为: ps auxw | wc -l 获取当前执行进程总数的源代码例如以下: #include <stdio.h> #include <stdlib.h&g ...
- PHP连接数据库(注冊页面的增删改查)
1.连接数据库 ---------–connect.php--------------– <?php //本地測试 $host = '127.0.0.1'; $port = 3306; $use ...