题目链接:http://lightoj.com/volume_showproblem.php?problem=1044

dp[i][j]表示i到j直接的最小回文区间个数,直接看代码

 #include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + ;
int dp[N][N], inf = 1e9;
char str[N];
bool judge(int l, int r) {
for(int i = l - , j = r - ; i < j; ++i, --j) {
if(str[i] != str[j])
return false;
}
return true;
}
int dfs(int l, int r) {
if(l == r)
return dp[l][l] = ;
if(l > r)
return ;
if(dp[l][r] < inf)
return dp[l][r];
int ans = inf;
for(int i = r; i >= l; --i) {
if(judge(i, r))
ans = min(ans, dfs(l, i - ) + );
}
return dp[l][r] = ans;
} int main()
{
int t;
scanf("%d", &t);
for(int ca = ; ca <= t; ++ca) {
scanf("%s", str);
int len = strlen(str);
for(int i = ; i <= len; ++i) {
for(int j = ; j <= len; ++j) {
dp[i][j] = inf;
}
}
printf("Case %d: %d\n",ca, dfs(, len));
}
return ;
}

Light oj 1044 - Palindrome Partitioning(区间dp)的更多相关文章

  1. light oj 1422 Halloween Costumes (区间dp)

    题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...

  2. Light OJ 1031 - Easy Game(区间dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1031 题目大意:两个选手,轮流可以从数组的任意一端取值, 每次可以去任意个但仅 ...

  3. Light OJ 1033 - Generating Palindromes(区间DP)

    题目大意: 给你一个字符串,问最少增加几个字符使得这个字符串变为回文串.   ============================================================= ...

  4. Light OJ 1422 - Halloween Costumes(区间DP 最少穿几件)

    http://www.cnblogs.com/kuangbin/archive/2013/04/29/3051392.html http://www.cnblogs.com/ziyi--caolu/a ...

  5. Lightoj 1044 - Palindrome Partitioning (DP)

    题目链接: Lightoj  1044 - Palindrome Partitioning 题目描述: 给一个字符串,问至少分割多少次?分割出来的子串都是回文串. 解题思路: 先把给定串的所有子串是不 ...

  6. lightoj 1044 - Palindrome Partitioning(需要优化的区间dp)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 题意:求给出的字符串最少能分成多少串回文串. 一般会想到用区间dp暴力3个for ...

  7. 1044 - Palindrome Partitioning(区间DP)

    题目大意: 给你一个字符串,问这个字符串最少有多少个回文串. 区间DP直接搞     #include<cstdio> #include<cstring> #include&l ...

  8. HDU4632:Palindrome subsequence(区间DP)

    Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...

  9. 131. Palindrome Partitioning (Back-Track, DP)

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

随机推荐

  1. sql中比较大小

    if object_id('tempdb..#dataOldNew1') is not null drop table #dataOldNew1 select distinct store_cd ,i ...

  2. oracle 11g 版本自带移除,省时省力

    ---oracle删除 app\Administrator\product\11.2.0\dbhome_1\deinstall.bat 指定要取消配置的所有单实例监听程序 [LISTENER]: En ...

  3. laravel5.2总结--数据库操作

    1 配置信息 1.1配置目录: config/database.php 1.2配置多个数据库 //默认的数据库 'mysql' => [ 'driver' => 'mysql', 'hos ...

  4. 设计模式之第9章-原型模式(Java实现)

    设计模式之第9章-原型模式(Java实现) “快到春节了,终于快放假了,天天上班好累的说.”“确实啊,最近加班比较严重,项目快到交付了啊.”“话说一到过节,就收到铺天盖地的短信轰炸,你说发短信就发吧, ...

  5. IOS开发学习笔记007-数据结构

    目录: 1.全局变量和局部变量 2.结构体 3.结构体数组 4.结构体做函数参数 5.结构体指针 6.枚举 7.总结 一.全局变量和局部变量 全局变量和局部变量的区别 1. 全局变量,再函数外定义的变 ...

  6. 转:vc与界面开发之间的文章

    [很好的一篇文章,很喜欢看同行的心路历程:http://www.vckbase.com/index.php/nv/444.html] 本屌丝在新春放假期间闲来无事,在各大编程论坛溜达了一圈.发现年前的 ...

  7. python的重重之器(生成器、迭代器、装饰器)

    一.装饰器 1.定义:本质是函数,装饰其他函数就是为其他函数添加附件功能. 2.原则: a.不能修改被装饰的函数的源代码: b.不能修改被装饰的函数的调用方式: 实例: #!/usr/bin/env ...

  8. [oldboy-django][2深入django]后台生成form标签并设置标签的属性

    # Form生成html标签 a. 通过Form生成Input输入框,Form标签,以及submit标签还是要在前端写的, 但是Form标签内的Input标签可以在后台实现:只需要按以下步骤 - vi ...

  9. 【转】iTween for Unity

    http://www.cnblogs.com/zhaoqingqing/p/3833321.html?utm_source=tuicool&utm_medium=referral 你曾经在你的 ...

  10. eclipse删除svn下载的文件后如何恢复

    Team右键-->与资源库同步-->覆盖/更新