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. 转:使用linq to sql 随机取一行数据的方法

    原文地址:http://outofmemory.cn/code-snippet/1760/usage-linq-to-sql-suiji-take-yixing-data-method 虽然这看来已经 ...

  2. 黑马程序员_Java面向对象_异常

    6.异常 1.异常: 就是程序在运行时出现不正常的情况.问题也是现实生活中一个具体的事物,也可以通过Java的类进行描述,并封装成对象.Exception和Error的子类名都是以父类名作为后缀名. ...

  3. 解决Jenkins上git出现Timeout的问题

    Jenkins上现有的git插件并没有配置超时的选项,因此在clone项目时如果网络差会出现“ERROR: Timeout after 10 minutes”,导致无法继续构建. 网上找到一个解决方法 ...

  4. hdu 4586 Play the Dice(概率dp)

    Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equ ...

  5. HDU 4907 Task schedule

    对于询问q 假设q不存在直接输出q 否则输出后面第一个不存在的数 从2*10^5到1遍历一边ac #include<bits/stdc++.h> using namespace std; ...

  6. Grizzly开发Echoserver实战

    Grizzly开发Echoserver实战 作者:chszs,转载需注明. 博客主页:http://blog.csdn.net/chszs 用Java编写可伸缩的server应用是有难度的.用Java ...

  7. Android ActionBar详解(一):ActionBar概述及其创建

    在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个重要的内容,Action Bar主要是用于代替传统的标题栏,对于Android平板设备来说屏幕更大它的标题使 ...

  8. 网页搜索功能 多表搜索sql

    SELECT ID, Title, FromTableFROM (SELECT ID, ArticleName AS Title, 'Article' AS FromTable        FROM ...

  9. Android打开外部DB文件

    DB文件要放在Assets文件夹下,封装一个工具类,如下: package com.XX.DB; import java.io.File; import java.io.FileOutputStrea ...

  10. AngularJs练习Demo6

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...