public class Solution {
public int LongestPalindromeSubseq(string s) {
int[,] dp = new int[s.Length, s.Length]; for (int i = s.Length - ; i >= ; i--)
{
dp[i, i] = ;
for (int j = i + ; j < s.Length; j++)
{
if (s[i] == s[j])
{
dp[i, j] = dp[i + , j - ] + ;
}
else
{
dp[i, j] = Math.Max(dp[i + , j], dp[i, j - ]);
}
}
}
return dp[, s.Length - ];
}
}

https://leetcode.com/problems/longest-palindromic-subsequence/#/description

leetcode516的更多相关文章

  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. leetcode516 Longest Palindromic Subsequence

    思路: 区间dp. 实现: class Solution { public: int longestPalindromeSubseq(string s) { int n = s.length(); ] ...

随机推荐

  1. VC 写注册表

    BOOL Running() { HKEY hKey; LPCTSTR strRegPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion ...

  2. linux下 stat statfs 获取 文件 磁盘 信息

    stat函数讲解 表头文件:    #include <sys/stat.h>              #include <unistd.h> 定义函数:    int st ...

  3. graphlab 安装好后的导入配置

    本以为下好了的结果... 然后等个十几二十分钟... 关掉这个页面重新打开,再重新导入graphlab 貌似好了...但是,,, 发现是自己的文件放错盘了...在F盘... 然后就好啦~

  4. ural 2021 Scarily interesting!(贪心)

    2021. Scarily interesting! Time limit: 1.0 secondMemory limit: 64 MB This year at Monsters Universit ...

  5. Linux下安装scrapy包出错

    pip install -i https://pypi.douban.com/simple/ scrapy 出现错误: error: command 将依赖包装全. sudo apt-get inst ...

  6. 【Window Service】关于Window Service的两三事

    引言  Window Service通常用于寄宿WCF服务或者定时作业.下面记录一下它的用法. 创建 创建Window Service项目后,可以看到Program和Service1类.Program ...

  7. MariaDB Galera Cluster环境搭建及高可用测试

    一.服务器概况Galera Cluster需要至少三个节点,在此次实验过程中,三个节点IP地址:192.168.56.101192.168.56.102192.168.56.103OS为centos ...

  8. LeetCode OJ:Rotate Array(倒置数组)

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  9. vector map迭代器失效解决方案

    vector : iter = container.erase(iter);    //erase的返回值是删除元素下一个元素的迭代器 vector<int>::iterator it = ...

  10. SVN管理多个项目版本库 (windows,linux 通用)

    SVN管理多个项目版本库: . 安装SVN服务器软件,路径: C:\Program Files\Subversion . 在D盘创建svn根目录D:\SVN-CM . 在D:\SVN-CM下创建SVN ...