https://oj.leetcode.com/problems/palindrome-partitioning-ii/

给定一个串,让把它划分成子串,要求每个子串都是回文的。

动态规划:

设数组 ans(i)表示从0到 i 要经过的最小划分数,则

ans[i] = ans[k] + 1,如果 k 到 i 是回文的

            i - 1       ,如果 k 到 i 都不是回文的

class Solution{
public:
int minCut(string s)
{
const int n = s.size();
vector<int> ans;
ans.resize(n+);
vector<vector<bool> > isPal;
isPal.resize(n);
for(int i = ;i<n;i++)
isPal[i].resize(n); for(int i = ;i<=n;i++)
{
ans[i] = n - - i;
} for(int i = n-;i>=;i--)
for(int j = i; j<n;j++)
{
if(s[i] == s[j] &&(j-i< || isPal[i+][j-]))
{
isPal[i][j] = true;
ans[i] = min(ans[i],ans[j+]+);
}
}
return ans[];
}
};

LeetCode OJ-- Palindrome Partitioning II ***的更多相关文章

  1. 【leetcode】Palindrome Partitioning II

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

  2. 【leetcode】Palindrome Partitioning II(hard) ☆

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  3. [Leetcode][JAVA] Palindrome Partitioning II

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  4. leetcode 132. Palindrome Partitioning II ----- java

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  5. Java for LeetCode 132 Palindrome Partitioning II

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  6. Leetcode 132. Palindrome Partitioning II

    求次数的问题一般用DP class Solution(object): def minCut(self, s): """ :type s: str :rtype: int ...

  7. leetcode@ [131/132] Palindrome Partitioning & Palindrome Partitioning II

    https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every ...

  8. [LeetCode] 131. Palindrome Partitioning 回文分割

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  9. LeetCode:Palindrome Partitioning,Palindrome Partitioning II

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

  10. [LeetCode] Palindrome Partitioning II 解题笔记

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

随机推荐

  1. Python While循环、运算符以及一些基础运用

    1.循环语句 循环打印"人生苦短,我用python" while True: print("人生苦短,我用python") 利用While循环,打印1~10 c ...

  2. [译]The Python Tutorial#11. Brief Tour of the Standard Library — Part II

    [译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中 ...

  3. 学习python第二天 流程判断

    while循环age_of_Jim = 56 count = 0 #开始计数while True: #循环代码 if count ==3:#如果次数=3 break#退出 guess_age = in ...

  4. Python9-MySQL-Homework-day43

    表结构 SET NAMES utf8; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure f ...

  5. A计划 hdu2102(BFS)

    A计划 hdu2102 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国 ...

  6. TCP/IP网络编程之优于select的epoll(二)

    基于epoll的回声服务端 在TCP/IP网络编程之优于select的epoll(一)这一章中,我们介绍了epoll的相关函数,接下来给出基于epoll的回声服务端示例. echo_epollserv ...

  7. Django基于Pycharm开发之四[关于静态文件的使用,配置以及源码分析](原创)

    对于django静态文件的使用,如果开发过netcore程序的开发人员,可能会比较容易理解django关于静态文件访问的设计原理,个人觉得,这是一个middlerware的设计,但是在django中我 ...

  8. day15 CSS JS DOM初探

    居中  line-hight  是上下          text-line  是左右    实现一个返回顶部的功能: 1 先写好CSS 2 写动作JS 写一个悬浮菜单: <!DOCTYPE h ...

  9. Java -X命令

    C:\Users\Administrator>java -X -Xmixed 混合模式执行 (默认) -Xint 仅解释模式执行 -Xbootclasspath:<用 ; 分隔的目录和 z ...

  10. 安卓手机关闭底部键盘灯的方法(htc G11亲测有效)

    还在因为看电子书和看电影时键盘灯刺眼而苦恼吗?下面提供一个方法关闭键盘灯,让你轻松DIY! 1、手机必须先Root。使用RE管理器,按照这个路径,找到文件:brightness sys/devices ...