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.

思路: 除了用dp[i][j]记录从i到j是否是Palindrome,还要用cut[i]存储到i位置位置最少的cut数

class Solution {
public:
int minCut(string s) {
int len = s.length();
vector<vector<bool>> dp(len, vector<bool>(len, false));
vector<int> cut(len,);
for(int i = ; i < len; i++) dp[i][i]=true;
for(int i = ; i < len; i++){
cut[i]=cut[i-]+;
for(int j = ; j < i; j++){ //traverse the length
if(s[i]==s[j]){
if(j==i-) dp[j][i] = true;
else dp[j][i]=dp[j+][i-];
if(dp[j][i]){
if(j==) cut[i]=;
else cut[i]=min(cut[j-]+, cut[i]);
}
}
}
}
return cut[len-];
}
};

最新文章

  1. [转] eclipse SVN中文件修改后图标不变黑星解决
  2. No zuo no die:DDD 应对具体业务场景,Domain Model 重新设计
  3. ora-02292
  4. 【11】在operator=中处理“自我赋值”
  5. QSplashScreen开机画面(不断的repaint)
  6. jQuery.data的是jQuery的数据缓存系统
  7. C语言格式化输出,空位补0,空位补空格
  8. Web版记账本开发记录(二)开发过程遇到的问题小结1 对数据库的区间查询
  9. [转]How To Send Transactional Email In A NodeJS App Using The Mailgun API
  10. 【impala学习之一】impala
  11. 微信小程序实现滚动分页加载更多
  12. spring boot对输入的字符串进行html转码
  13. 字符串使用replaceAll()方法报异常
  14. JAVA类加载器概念与线程类加载器
  15. Xcode 8 插件安装
  16. 8086处理器的无条件转移指令——《x86汇编语言:从实模式到保护模式》读书笔记13
  17. LeetCode 141——环形链表
  18. AngularJs学习笔记(2)——ng-include
  19. django1.7 HTML模板中{%url%}的使用
  20. 才知道 Windows Live Writer Source Code plugin for SyntaxHighlighter 更新到2.0了

热门文章

  1. 1111 Online Map (30 分)
  2. Vue引用其他组件,但组件某些部分不需要时的简单处理
  3. Open Live writer 远程博客管理客户端
  4. oletools下载安装及rtfobj使用
  5. [datatable]关于在DataTable中执行DataTable.Select(&quot;条件&quot;)返回DataTable的解决方法
  6. 自己写的一个jQuery分页插件
  7. 第3章 文件I/O(3)_内核数据结构、原子操作
  8. storm的流分组
  9. 基于Linux的Samba开源共享解决方案测试(一)
  10. [Python] 分段线性插值