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的更多相关文章

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

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

  2. LeetCode:Palindrome Partitioning,Palindrome Partitioning II

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

  3. 【leetcode】Palindrome Partitioning II

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

  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[dp]

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

  7. 动态规划——Palindrome Partitioning II

    Palindrome Partitioning II 这个题意思挺好理解,提供一个字符串s,将s分割成多个子串,这些字串都是回文,要求输出分割的最小次数. Example:Input: "a ...

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

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

  9. LeetCode: Palindrome Partitioning II 解题报告

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

随机推荐

  1. 【转】 boot.img的解包与打包

    原文网址:http://blog.csdn.net/wh_19910525/article/details/8200372 Android 产品中,内核格式是Linux标准的zImage,根文件系统采 ...

  2. [VBA]用一个简单例子说明如何在Excel中自定义函数

    Excel中的函数无疑是强大的,但是再强大的战士也有他脆弱的脚后跟[1].这两天在使用Excel的时候遇到了一个需求,要在某一个单元格里面自动计算今天是星期几(如显示 Today is Tuesday ...

  3. JVM基础和调优(四)

    垃圾回收算法中的一些问题 再上一遍中,说道JVM并不是采用一种垃圾回收的方法,因为不同的内存块采取的方法是不样的,那么:为什么要分块?为什么不采用同一种方法回收垃圾,这样不是更加的统一吗? 分块的垃圾 ...

  4. PHP数据结构:栈、队列、堆、固定数组

    数据结构:栈 队列: 堆: 固定尺寸的数组:

  5. [iOS] Create TableView & customize UITableViewCell

    1. First artical, notice the last thing - Connecting the DataSource and Delegate: http://www.appcoda ...

  6. Entify Framewrok - 学习链接

    http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6-loading- ...

  7. (转载)iOS Framework: Introducing MKNetworkKit

    This article is available in Serbo-Croatian,  Japanese and German. (Translations in Serbo-Croatian b ...

  8. How to face setbacks

    I’ve been in a bad mood since I started on the American Accent. I became even more upset when I adde ...

  9. LeetCode 58 Spiral Matrix II

    Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...

  10. UICollectionView的基本使用

    这个控件,看起来与UITableView有点像,而且基本的用法也很相像哦!!! 我们来看看API: #pragma mark - UICollectionViewDataSource // 指定Sec ...