LeetCode_Palindrome Partitioning II
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.
分析: D[i] = 区间[i,n)之间最小的cut数,n为字符串长度, 则,D[i] = min(D[i],1+D[j+1]) i<=j <n
P[i][j] = str[i] == str[j] && P[i+1][j-1];
class Solution {
public:
int minCut(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int len = s.size();
if(len < ) return ;
vector<vector<bool>> flag(len, vector<bool>(len, false)) ;
vector<int> dp(len+);
for(int i = ; i<= len ; i++)
dp[i] = len - i;
for(int i = len - ; i >= ; i--)
for(int j = i; j < len ; j++)
if(s[i] == s[j] &&(j-i< || flag[i+][j-] ) )
{
flag[i][j] = true;
dp[i] = dp[i] < dp[j+] + ? dp[i] : dp[j+] + ;
}
return dp[]-;
}
};
LeetCode_Palindrome Partitioning II的更多相关文章
- 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@ [131/132] Palindrome Partitioning & Palindrome Partitioning II
https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every ...
- [LeetCode] Palindrome Partitioning II 解题笔记
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- LeetCode-Palindrome Partitioning II[dp]
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- 动态规划——Palindrome Partitioning II
Palindrome Partitioning II 这个题意思挺好理解,提供一个字符串s,将s分割成多个子串,这些字串都是回文,要求输出分割的最小次数. Example:Input: "a ...
- leetcode 131. Palindrome Partitioning 、132. Palindrome Partitioning II
131. Palindrome Partitioning substr使用的是坐标值,不使用.begin()..end()这种迭代器 使用dfs,类似于subsets的题,每次判断要不要加入这个数 s ...
- LeetCode: Palindrome Partitioning II 解题报告
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
随机推荐
- CCI_chapter 8 Recurision
8.1 水题 8.2 Imagine a robot sitting on the upper left hand corner of an NxN grid The robot can only m ...
- CCI_chapter 1
1.1Implement an algorithm to determine if a string has all unique characters What if you can not us ...
- translate函数说明
TRANSLATE(expr, from_string, to_string) from_string 与 to_string 以字符为单位,对应字符一一替换. SQL> SELECT TRAN ...
- 【转】使用 vim + ctags + cscope + taglist 阅读源码
原文网址:http://my.oschina.net/u/554995/blog/59927 最近,准备跟学长一起往 linux kernel 的门里瞧瞧里面的世界,虽然我们知道门就在那,但我们还得找 ...
- Kuhn-Munkres算法。带权二分图匹配模板 (bin神小改版本)
/****************************************************** 二分图最佳匹配 (kuhn munkras 算法 O(m*m*n)). 邻接矩阵形式 . ...
- pyglet: a cross-platform windowing and multimedia
pyglet pyglet: a cross-platform windowing and multimedia library for Python.
- HDU 2689 sort it - from lanshui_Yang
Problem Description You want to processe a sequence of n distinct integers by swapping two adjacent ...
- DDMS files not found: tools\hprof-conv.exe
最近在Eclipse下每次更新ADT和SDK后都报一些错误,比如 DDMS files not found: D:\android-sdk-windows-1.6_r1\android-sdk-win ...
- Citrix 服务器虚拟化之十 Xenserver高可用性HA
Citrix 服务器虚拟化之十 Xenserver高可用性HA HA是一套全自动功能设计,规划.它可以安全地恢复出现问题的XenServe 主机.例如物理破坏网络或主机的硬件故障,HA可确保无需任何人 ...
- Android 自定义UI--电池
首先看一下效果图, 下面看代码: /** * */ package com.example.batterydemo; import android.content.Context; import an ...