题目大意:
给你一个字符串,问这个字符串最少有多少个回文串。
区间DP直接搞
 
 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int MAXN = ;
int dp[MAXN][MAXN];
bool P[MAXN][MAXN];
char str[MAXN];
int DFS(int L,int R)
{
if(dp[L][R] != -)
return dp[L][R];
if(L >= R)
return dp[L][R] = ; dp[L][R] = INF;
if(P[L][R]) dp[L][R] = ;
for(int i=L; i<=R; i++)
{
if(P[L][i])
dp[L][R] = min(dp[L][R], + DFS(i+,R));
}
return dp[L][R];
} bool ok(int L,int R)
{
for(int i=L,j=R; i<=j; i++, j--)
{
if(str[i] != str[j])
return false;
}
return true;
} int main()
{
int T, cas = ;
scanf("%d", &T);
while(T --)
{
memset(dp, -, sizeof(dp));
scanf("%s", str);
int len = strlen(str) - ;
for(int i=; i<=len; i++)
for(int j=i; j<=len; j++)
P[i][j] = ok(i, j); printf("Case %d: %d\n",cas ++, DFS(, len) );
} return ;
}

1044 - Palindrome Partitioning(区间DP)的更多相关文章

  1. Lightoj 1044 - Palindrome Partitioning (DP)

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

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

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

  3. HDU4632:Palindrome subsequence(区间DP)

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

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

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

  5. Cheapest Palindrome(区间DP)

    个人心得:动态规划真的是够烦人的,这题好不容易写出了转移方程,结果超时,然后看题解,为什么这些题目都是这样一步一步的 递推,在我看来就是懵逼的状态,还有那个背包也是,硬是从最大的V一直到0,而这个就是 ...

  6. Leetcode_1278. Palindrome Partitioning III_[DP]

    题目链接 You are given a string s containing lowercase letters and an integer k. You need to : First, ch ...

  7. Leetcode_132. Palindrome Partitioning II_[DP]

    题目链接 Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...

  8. HDU 4632 Palindrome subsequence(区间dp,回文串,字符处理)

    题目 参考自博客:http://blog.csdn.net/u011498819/article/details/38356675 题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. ...

  9. HDU 4632 Palindrome subsequence (区间DP)

    题意 给定一个字符串,问有多少个回文子串(两个子串可以一样). 思路 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字符串中[i,j]位置中出现的回文子序 ...

随机推荐

  1. Nunit概要

    一.NUnit是一个单元测试框架,专门针对于.NET来写的.其实在前面有JUnit(Java),CPPUnit(C++),他们都是xUnit的一员.最初,它是从JUnit而来.现在的版本是2.2.接下 ...

  2. display: inline-block 的神奇效果

    先上要实现的效果图: 方案一:来自卢兄: <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  3. 解决Visual Studio 找不到报表控件、rdlc中文乱码

    找回报表控件 运行安装程序中的 ..\packages\Reporting Services\RVAddon.msi 工具栏,右键选择ReportViewer,注意选择的版本 如果不能编辑报表文件(. ...

  4. OpenXML: Asp.net利用OpenXML 导出Excel.

    http://www.cnblogs.com/skyfei/archive/0001/01/01/Openxml.html

  5. webrtc学习———记录三:mediaStreamTrack

    参考: https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack 转自http://c.tieba.baidu.com/p/3 ...

  6. [IO] C# DirFileHelper文件与文件夹操作类教程与源码下载 (转载)

    点击下载 DirFileHelper.zip 主要功能如下所示 // 摘要: // 向文本文件的尾部追加内容 // // 参数: // filePath: // 文件的绝对路径 // // conte ...

  7. [DEncrypt] HashEncode--哈希加密帮助类 (转载)

    点击下载 HashEncode.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.HashEncode 得到随机哈希加密字符串2.HashEncode 得到一个随机数值3.HashEncod ...

  8. 黑马程序员-集合(二)contains()方法的内部探索

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 我们知道集合是用来存储对象的.在他们实现了众多的接口我们以Arraylist为列子 所有已实现的 ...

  9. Java线程:新特征-线程池

    Sun在Java5中,对Java线程的类库做了大量的扩展,其中线程池就是Java5的新特征之一,除了线程池之外,还有很多多线程相关的内容,为多线程的编程带来了极大便利.为了编写高效稳定可靠的多线程程序 ...

  10. CSDN Oracle版精华帖荟萃

    ⑴ 关于大数据量的数据库设计问题http://bbs.csdn.net/topics/390382930⑵ ORA-00904标识符无效http://bbs.csdn.net/topics/39033 ...