Given a string s, partition s such that every substring of the partition is a palindrome.

Return the minimum cuts needed for a palindrome partitioning of s.

For example, given s = "aab",
Return 1 since the palindrome partitioning ["aa","b"] could be produced using 1 cut.

思路: 除了用dp[i][j]记录从i到j是否是Palindrome,还要用cut[i]存储到i位置位置最少的cut数

class Solution {
public:
int minCut(string s) {
int len = s.length();
vector<vector<bool>> dp(len, vector<bool>(len, false));
vector<int> cut(len,);
for(int i = ; i < len; i++) dp[i][i]=true;
for(int i = ; i < len; i++){
cut[i]=cut[i-]+;
for(int j = ; j < i; j++){ //traverse the length
if(s[i]==s[j]){
if(j==i-) dp[j][i] = true;
else dp[j][i]=dp[j+][i-];
if(dp[j][i]){
if(j==) cut[i]=;
else cut[i]=min(cut[j-]+, cut[i]);
}
}
}
}
return cut[len-];
}
};

132. Palindrome Partitioning II (String; DP)的更多相关文章

  1. leetcode 131. Palindrome Partitioning 、132. Palindrome Partitioning II

    131. Palindrome Partitioning substr使用的是坐标值,不使用.begin()..end()这种迭代器 使用dfs,类似于subsets的题,每次判断要不要加入这个数 s ...

  2. 【LeetCode】132. Palindrome Partitioning II

    Palindrome Partitioning II  Given a string s, partition s such that every substring of the partition ...

  3. leetcode 132. Palindrome Partitioning II ----- java

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  4. 132. Palindrome Partitioning II

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  5. Java for LeetCode 132 Palindrome Partitioning II

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  6. 【leetcode dp】132. Palindrome Partitioning II

    https://leetcode.com/problems/palindrome-partitioning-ii/description/ [题意] 给定一个字符串,求最少切割多少下,使得切割后的每个 ...

  7. 动态规划之132 Palindrome Partitioning II

    题目链接:https://leetcode-cn.com/problems/palindrome-partitioning-ii/description/ 参考链接:https://blog.csdn ...

  8. 132 Palindrome Partitioning II 分割回文串 II

    给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串.返回 s 符合要求的的最少分割次数.例如,给出 s = "aab",返回 1 因为进行一次分割可以将字符串 s 分 ...

  9. Leetcode 132. Palindrome Partitioning II

    求次数的问题一般用DP class Solution(object): def minCut(self, s): """ :type s: str :rtype: int ...

随机推荐

  1. 杂项-自动化测试工具:Selenium(浏览器自动化测试框架)

    ylbtech-杂项-自动化测试工具:Selenium(浏览器自动化测试框架) Selenium 是一个用于Web 应用程序测试的工具.Selenium 测试直接运行在浏览器中,就像真正的用户在操作一 ...

  2. [转]C#鼠标拖动任意控件

    C#鼠标拖动任意控件(winform) 分类: c#2011-08-15 22:51 178人阅读 评论(0) 收藏 举报 winformc#userwindowsobjectapi using Sy ...

  3. Centos 的计划任务 crontab

    使用计划任务! crontab命令主要有3个参数: -e :编辑用户的crontab. -l :列出用户的crontab的内容. -r :删除用户的crontab的内容. 执行crontab -e,将 ...

  4. VMware仅主机模式访问外网

    原文转载至:https://blog.csdn.net/eussi/article/details/79054622 保证VMware Network Adapter VMnet1是启用状态  将可以 ...

  5. 自己写的jQuery浮动广告插件

    效果图: 文件位置摆放: 插件的js代码: $.extend({ pfAdv:function(options){ var defaults={ count:1, startTop:200, star ...

  6. web前端开发企业级CSS常用命名,书写规范总结

    1.常用命名 标题: title 摘要: summary 箭头: arrow 商标: label 网站标志: logo 转角/圆角: corner 横幅广告: banner 子菜单: subMenu ...

  7. 笔记本电脑安装centos 7(转)

    1. 下载 CentOS 镜像 下载地址 : https://wiki.centos.org/Download, 我下载的是1406 2. 使用 UltraISo 将镜像刻录到U盘 UltraISo  ...

  8. ORM创建 脚本运行

  9. html-字体

    字体大小 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  10. linux计划任务crontab的使用

    参考网站:https://www.cnblogs.com/intval/p/5763929.html 编辑计划任务:    crontab -e 查看计划任务:    crontab -l 使用实例: ...