【leetcode】Palindrome Partitioning II
Palindrome Partitioning II
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.
class Solution {
public:
int minCut(string s) {
int n=s.length();
vector<vector<bool> > isP(n,vector<bool>(n,false));
for(int i=n-;i>=;i--)
{
for(int j=i;j<n;j++)
{
if(s[i]==s[j]&&(j-i<=||isP[i+][j-])) isP[i][j]=true;
}
}
vector<int> dp(n+);
dp[n]=-; //注意边界条件,表示了dp[i]无需分割时,dp[i]=dp[n]+1=0;
for(int i=n-;i>=;i--)
{
int minCut=INT_MAX;
for(int k=i+;k<n+;k++)
{
if(isP[i][k-]&&minCut>dp[k]+)
{
dp[i]=dp[k]+;
minCut=dp[i];
}
}
}
return dp[];
}
};
【leetcode】Palindrome Partitioning II的更多相关文章
- 【leetcode】Palindrome Partitioning II(hard) ☆
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 【LeetCode】Palindrome Partitioning 解题报告
[题目] Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...
- 【leetcode】Palindrome Partitioning
Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...
- 【LeetCode】47. Permutations II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:回溯法 日期 题目地址:htt ...
- 【LeetCode】90. Subsets II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 回溯法 日期 题目地址:https://leet ...
- 【leetcode刷题笔记】Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 【Leetcode】【Medium】Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- 【leetcode】 Palindrome Partitioniong (middle) (*^__^*)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- [Leetcode][JAVA] Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
随机推荐
- [转]SQL注入攻防入门详解
原文地址:http://www.cnblogs.com/heyuquan/archive/2012/10/31/2748577.html =============安全性篇目录============ ...
- BZOJ-1925 地精部落 烧脑DP+滚动数组
1925: [Sdoi2010]地精部落 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1053 Solved: 633 [Submit][Status ...
- Android视频直播解决方案(rstp、udp)
做局域网视频直播有两种方案,通过rstp或udp协议. 1.rstp协议,网络上有个开源项目,基于Android,且这个项目也是一个服务端,里面也集成了http访问页面,可以通过http或者rstp直 ...
- jsp中 response和request区别
1.response 属于重定向请求: 其地址栏的URL会改变: 会向服务器发送两次请求: 2. request 属于请求转发: 其地址栏的URL不会改变: 向服务器发送一次请求: 举一个区分它们的简 ...
- 如何配置Filter过滤器处理JSP中文乱码
参考Tomcat服务器目录webapps的examples示例 简单配置步骤:1.在项目web.xml文件添加过滤器标记<filter>和<filter-mapping>:2. ...
- iBatisnet系列(二) 配置运行环境和日志处理
http://hjf1223.cnblogs.com/archive/2006/04/24/383119.aspx 刚爬完鼓山回来,想到这篇刚刚开始,不敢怠慢,洗完澡休息一下就到电脑旁边来了.现在我开 ...
- Jquery 表单操作
文本框,文本区域: 获取值: 1.$("#txt").attr("value"); 2. $("txt").val(); 单选按钮: 获取值 ...
- try catch finally执行顺序
1.不管有木有出现异常,finally块中代码都会执行: 2.当try和catch中有return时,finally仍然会执行: 3.finally是在return表达式运算后前执行的,所以函数返回值 ...
- 导入安全证书到jdk步骤详细说明-原
一.首先要在浏览器打开需要证书的网站,然后把证书下载下来,保存的证书名称随意命名,只要保证唯一性(这个唯一性下文有解释) 二.然后把证书复制到%JAVA_HOME%/jre/bin/路径下,即保证证书 ...
- R-squared是什么意思
在回归分析中,R-squared值应该为多大? 就像经常被问到,在回归分析中,R平方应该为多大才表示回归模型是好的?我经常能够听到这类问题,在没回答这个问题之前,我会解释如 何来解释R平方值,我也会阐 ...