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", Return1since the palindrome partitioning["aa","b"]could be produced using 1 cut.

C++

class Solution {
public:
int minCut(string s) {
int n = s.size();
if(n < 2) return 0;
vector<int> dp(n, INT_MAX);
vector<bool> tmp(n, false);
vector<vector<bool> > p(n, tmp);
for(int i=0; i<n; i++){
for(int j=i; j>-1; j--){
if(s[i] == s[j] && (i-j < 2 || p[j+1][i-1])){
p[j][i] = true;
dp[i] = min(dp[i], j == 0? 0 : dp[j-1] + 1);
}
}
}
return dp.back();
}
};

palindrome-partitioning-ii leetcode C++的更多相关文章

  1. Palindrome Partitioning II Leetcode

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

  2. Palindrome Partitioning II Leetcode java

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

  3. LeetCode:Palindrome Partitioning,Palindrome Partitioning II

    LeetCode:Palindrome Partitioning 题目如下:(把一个字符串划分成几个回文子串,枚举所有可能的划分) Given a string s, partition s such ...

  4. leetcode@ [131/132] Palindrome Partitioning & Palindrome Partitioning II

    https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every ...

  5. [LeetCode] Palindrome Partitioning II 解题笔记

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

  6. 【leetcode】Palindrome Partitioning II

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

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

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

  8. LeetCode: Palindrome Partitioning II 解题报告

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

  9. 【LeetCode】132. Palindrome Partitioning II

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

  10. 19. Palindrome Partitioning && Palindrome Partitioning II (回文分割)

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

随机推荐

  1. html input选择文件后将文件转为地址

    function getObjectURL(file) { var url = null; if (window.createObjectURL != undefined) { // basic ur ...

  2. jmeter 录制排除模式

    jmeter录制时,静态的资源不需要,可以在录制的时候直接排除. .*\.(bmp|css|js|gif|icov|jpeg|png|swf|woff|woff2|htm|html).* .*\.(j ...

  3. mimikatz使用笔记

    一.获取密码# privilege::debug sekurlsa::logonpasswords mimikatz.exe "sekurlsa::debug" "sek ...

  4. 题解 [ZJOI2016]大森林

    题目传送门 Description 现在有 \(n\) 棵以 \(1\) 为根的树,每棵树有一个生长节点,有 \(m\) 次操作,每次操作是下面三种中的一个: 在 \(l\sim r\) 的这些树的生 ...

  5. 题解 [HNOI2016]大数

    题目传送门 题目大意 给出一个\(n\)个数的字符串,有\(m\)次查询,对于该串的子串\([l,r]\)有多少个子串满足是固定素数\(p\)的倍数. 思路 其实很简单,但是一开始想偏了...果然还是 ...

  6. bzoj4821 && luogu3707 SDOI2017相关分析(线段树,数学)

    题目大意 给定n个元素的数列,每一个元素有x和y两种元素,现在有三种操作: \(1\ L\ R\) 设\(xx\)为\([l,r]\)的元素的\(x_i\)的平均值,\(yy\)同理 求 \(\fra ...

  7. Visual Studio Debug only user code with Just My Code

    Debug only user code with Just My Code By default, the debugger skips over non-user code (if you wan ...

  8. 笨方法学python中执行argv提示ValueError: not enough values to unpack (expected 4, got 1)

    解决方法:选择Terminal中输入执行ex13.py 1 2 3 执行结果如下图

  9. 初学Python-day10 函数2

    函数 1.函数也是一种数据 函数也是一种数据,可以使用变量保存 回调函数(参数的值还是一个函数) 实例: def test(): print('hello world') def test1(a): ...

  10. 分布式表示(Distributed Representation)

    NLP模型笔记 - 分布式表示 ziuno 2020-03-08 19:52:50 410 收藏 2 分类专栏: NLP 模型 笔记 文章标签: nlp 最后发布:2020-03-08 19:52:5 ...