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. CCI_chapter 4 trees and Grapths

    4.1Implement a function to check if a tree is balanced For the purposes of this question,a balanced ...

  2. hdu4623:crime 数学优化dp

    鞍山热身赛的题,也是去年多校原题 题目大意: 求n个数的排列中满足相邻两个数互质的排列的数量并取模 当时的思路就是状压dp.. dp[i][state]  state用二进制记录某个数是否被取走,i ...

  3. <php>Ajax基本格式

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  4. Spring 小示例

    通过一个简单的示例来初步理解Spring框架 1.创建java工程,导入相应Spring包,放在lib文件夹中 2.接口  IHelloMessage package com.jike.spring. ...

  5. jdbc调用mysql存储过程实现代码带有输入和输出

    转载自 http://www.jb51.net/article/34747.htm 1. 创建存储过程 建立一个MySQL的存储过程 add_pro 复制代码代码如下: delimiter // dr ...

  6. swift 点击button改变其内填充图片,达到选中的效果

    先看下效果: 点击后: 实现:在页面拖一个button,然后在所在页面声明其变量和一个点击事件 声明: @IBOutlet weak var BtnZiDong: UIButton! 点击事件函数: ...

  7. bootstrap学习以及其插件

    Bootstrap中文网地址,里面有bootstrap组件的下载与使用说明,现在使用bootstrap3: http://www.bootcss.com/ W3CSchool.CC里面有学习boots ...

  8. hdu2767 Proving Equivalences --- 强连通

    给一个图,问至少加入�多少条有向边能够使图变成强连通的. 原图是有环的,缩点建图,在该DAG图上我们能够发现,要使该图变成强连通图必须连成环 而加入�最少的边连成环,就是把图上入度为0和出度为0的点连 ...

  9. java后台訪问url连接——HttpClients

    java后台訪问url,并传递数据--通过httpclient方式 须要的包,包可能多几个额外的,假设无用或者冲突删除就可以.httpclient是使用的是4.4.1的版本号:http://downl ...

  10. 设置c#windows服务描述及允许服务与桌面交互的几种方法(转)

    方法一: 在ProjectInstaller.cs重写 install() ,Uninstall()方法 public override void Install(IDictionary stateS ...