最长回文序列(返回长度)
2015-10-23 00:15
260 查看
int solve(const string &s,int l,int r) { if(l==r) return 1; if(s[l]==s[r]){ if(l+1==r) return 2; else return solve(s,l+1,r-1)+2; } return max(solve(s,l+1,r),solve(l,r-1)); }
// Everay single character is a palindrom of length 1 L(i, i) = 1 for all indexes i in given sequence // IF first and last characters are not same If (X[i] != X[j]) L(i, j) = max{L(i + 1, j),L(i, j - 1)} // If there are only 2 characters and both are same Else if (j == i + 1) L(i, j) = 2 // If there are more than two characters, and first and last // characters are same Else L(i, j) = L(i + 1, j - 1) + 2
相关文章推荐
- java基础——Java概述
- Gnome3提取gnome-shell.css以及修改和编译
- swift 学习笔记 --> Dictionary
- AndroidManifest.xml中为啥android:name的值前面要加上点号
- C++拷贝构造函数详解
- Fast RCNN 训练自己数据集 (2修改数据读取接口)
- LeetCode 28: Implement strStr()
- 生日相同 2.0
- Could not obtain information about Windows NT group/user 'xxxx\xxxx', error code 0x5
- 【Android效果集】下雨效果
- Cocos2d入门--2--三角函数的应用
- 《HBase权威指南》读书笔记5:第五章 客户端API: 管理功能
- HDU4279(数论)
- easyui-datagrid 两次请求
- angular+bootstrap+MVC 之二,模态窗
- 时间线制作
- leetcode之Kth Largest Element in an Array
- AndroidManifest.xml文件解析
- 2015-10-22 常用dos命令
- leetcode笔记:Binary Tree Zigzag Level Order Traversal