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. FJ省队集训DAY4 T2

    XXX #include<cstdio> #include<iostream> #include<cmath> #include<cstring> #i ...

  2. Linux Shell逻辑运算符和表达式详解

    Shell 逻辑运算符涉及以下几种类型,只要适当选择,可以解决我们很多复杂的判断,达到事半功倍效果. 一.逻辑判断1.关于文件与目录的逻辑判断-f 常用.判断『文件』是否为普通文件,比如: if [ ...

  3. rdesktop命令连接Win7远程桌面

    1. 开启远程服务,并添加远程桌面用户: 2. 远程桌面开启失败,如果远程桌面开启失败,到服务控制台里面去找到“remote desktop services”依赖的几个服务,是不是被禁用了.都开启一 ...

  4. cf413E Maze 2D

    E. Maze 2D time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  5. poj3708:函数式化简+高精度进制转换+同余方程组

    题目大意 给定一个函数 找出满足条件   等于 k 的最小的x m,k,d已知 其中 m,k 很大需要使用高精度存储 思路: 对 函数f(m)进行化简 ,令t=ceil( log(d,m) ) 可以得 ...

  6. (转)iOS7人机界面设计规范 - 目录

    英文原文出自苹果官方的iOS7设计资源-iOS人机界面设计规范(预发布版本),由C7210自发翻译,并首发于Beforweb.com.如需转载,请注明译者及出处信息. UI设计基础 为iOS7而设计 ...

  7. Qt on Android:让 Qt Widgets 和 Qt Quick 应用全屏显示

    Android 系统版本号非常多,较新的 4.4 ,较老的 2.3 ,都有人用. Qt on Android 开发的 Android 应用.默认在 Android 设备上是非全屏的. 而有些应用的需求 ...

  8. Android仿IOS回弹效果 ScrollView回弹 总结

    Android仿IOS回弹效果  ScrollView回弹 总结 应项目中的需求  须要仿IOS 下拉回弹的效果 , 我在网上搜了非常多 大多数都是拿scrollview 改吧改吧 试了一些  发现总 ...

  9. ado.net数据库操作(1)

    这些都是网上搜索到的,我把他放在自己的博客里,作为笔记 1.1创建数据库连接(sqlserver) <%@ Import Namespace="System.Data" %& ...

  10. (转)怎样查看局域网中自己的IP地址和其他电脑的IP地址?

    开始菜单->运行->打cmd,回车->再弹出的黑框里打ipconfig -all,回车显示的IP Address就是你的ip地址看局域网的电脑的ip用软件比较方便,比如p2p终结者, ...