132.leecode-Palindrome Partitioning II
这个题需要两个dp,一个保存从i到j是否为回文串
另一个保存0到i的最小的分割
下面是我的效率不太高的代码
class Solution {
public:
int minCut(string s) {
vector<vector<bool> > dp(s.size(), vector<bool>(s.size(), false));
vector<int> res(s.size(), );
//辅助数组
for(int i = ; i < s.size(); i++)
{
for(int j = i, k = ; j < s.size(); j++, k++)
{
if(j-k <= )
dp[k][j] = s[k] == s[j] ? true : false;
else
dp[k][j] = (s[k] == s[j]) && (dp[k+][j-]);
}
}
//如果0-i是回文串,那么不用切res[i]为0
//如果j-i是回文串,那么res[i]为res[j-1]+1
res[] = ;
for(int i = ; i < s.size(); i++)
{
res[i] = i;
for(int j = ; j <= i; j++)
{
if(dp[j][i])
res[i] = j == ? : min(res[i], res[j-] + );
}
}
return res[s.size()-];
}
};
132.leecode-Palindrome Partitioning II的更多相关文章
- leetcode@ [131/132] Palindrome Partitioning & Palindrome Partitioning II
https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every ...
- leetcode 131. Palindrome Partitioning 、132. Palindrome Partitioning II
131. Palindrome Partitioning substr使用的是坐标值,不使用.begin()..end()这种迭代器 使用dfs,类似于subsets的题,每次判断要不要加入这个数 s ...
- 【LeetCode】132. Palindrome Partitioning II
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- 19. Palindrome Partitioning && Palindrome Partitioning II (回文分割)
Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...
- LeetCode:Palindrome Partitioning,Palindrome Partitioning II
LeetCode:Palindrome Partitioning 题目如下:(把一个字符串划分成几个回文子串,枚举所有可能的划分) Given a string s, partition s such ...
- 【leetcode】Palindrome Partitioning II
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- [LeetCode] Palindrome Partitioning II 解题笔记
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 动态规划——Palindrome Partitioning II
Palindrome Partitioning II 这个题意思挺好理解,提供一个字符串s,将s分割成多个子串,这些字串都是回文,要求输出分割的最小次数. Example:Input: "a ...
- LeetCode: Palindrome Partitioning II 解题报告
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- leetcode132. Palindrome Partitioning II
leetcode132. Palindrome Partitioning II 题意: 给定一个字符串s,分区使分区的每个子字符串都是回文. 返回对于s的回文分割所需的最小削减. 例如,给定s =&q ...
随机推荐
- mysql学习笔记--go使用mysql
一. 连接数据库 a. //用户名:密码@[连接方式](主机名:端口号)/数据库名 db,_:=sql.Open("mysql","root:7758521123jf@( ...
- QVariant类
QVariant类: #include "widget.h" #include <QApplication> #include <QDebug> int m ...
- pandas用法之二
1,函数应用 ①map() 将函数作用于一个Series的每一个函数(不能是DataFrame) 类似于Python的高阶函数map() 函数可以是Numpy中的通用函数,也可以是自定义函数 优点:代 ...
- 20164319 刘蕴哲 Exp3 免杀原理与实践
[实验内容] 1.1 正确使用msf编码器(0.5分),msfvenom生成如jar之类的其他文件(0.5分),veil-evasion(0.5分),加壳工具(0.5分),使用shellcode编程( ...
- android 7.0 调用系统相机崩溃的解决方案(非谷歌官方推荐)
解决方案: 1.(推荐)7.0之后你的app就算有权限,给出一个URI之后手机也认为你没有权限. 不用修改原有代码,在Application的oncreate方法中:(或者直接放在调用相机的activ ...
- weex h5开发区别-实践初级篇
html标签 weex中没有标签的概念,html中标签对应于weex中的Components weex 无<span> .<p> ,用<text>替代.但是< ...
- rabbit基本原理 转
https://www.cnblogs.com/jun-ma/p/4840869.html
- elementUI表格排序问题
elementUI表格排序: 问题:得不到排序后的数组,每次打印的总是一开始的数据 <el-table ref="passTable" :data="passTab ...
- mysql约束以及数据库的修改
一.约束 1.约束保证数据完整性和一致性. 2.约束分为表级约束和列级约束. (1)表级约束(约束针对于两个或两个以上的字段使用) (2)列级约束(针对于一个字段使用) 3.约束类型有: (1)NOT ...
- matplotlib中color可用的颜色
http://stackoverflow.com/questions/22408237/named-colors-in-matplotlib 参考网址给出了matplotlib中color可用的颜色: ...