题目链接:

  Lightoj  1044 - Palindrome Partitioning

题目描述:

  给一个字符串,问至少分割多少次?分割出来的子串都是回文串。

解题思路:

  先把给定串的所有子串是不是回文串处理出来,然后用dp[i] 表示 从起点到串i的位置的最少分割次数,然后结合处理出来的回文串转移一下即可!

  还是好蠢哦!自己竟然感觉是一个区间DP,但是n又那么大,完全不是区间DP的作风啊!

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std;
typedef long long LL;
const int maxn = ;
const int INF = 0x3f3f3f3f; int dp[maxn];
bool a[maxn][maxn];
char str[maxn];
int main ()
{
int T;
scanf ("%d", &T);
for (int t=; t<=T; t++)
{
scanf ("%s", str+);
memset(a, false, sizeof(a));
int len = strlen (str+); for (int i=; str[i]; i++)
a[i][i] = true; for (int i=; i<=len; i++)
for (int l=; l+i<=len+; l++)
{
int r = l + i - ;
if ((r == l + || a[l+][r-]) && str[l] == str[r]) a[l][r] = true;
else a[l][r] = false;
} dp[] = ;
for (int i=; i<=len; i++)
{
dp[i] = INF;
for (int j=; j<=i; j++)
if (a[j][i]) dp[i] = min (dp[i], dp[j-]+);
}
printf ("Case %d: %d\n", t, dp[len]);
}
return ;
}

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

  1. LightOJ 1044 Palindrome Partitioning(简单字符串DP)

    A palindrome partition is the partitioning of a string such that each separate substring is a palind ...

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

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

  3. Light oj 1044 - Palindrome Partitioning(区间dp)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 dp[i][j]表示i到j直接的最小回文区间个数,直接看代码 #include ...

  4. 1044 - Palindrome Partitioning(区间DP)

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

  5. D - Palindrome Partitioning (DP)

    Description A palindrome partition is the partitioning of a string such that each separate substring ...

  6. Atcoder Yet Another Palindrome Partitioning(状压dp)

    Atcoder Yet Another Palindrome Partitioning 思路: 一个字符串满足条件的情况是奇数字母个数小于等于1,也就是异或起来是1<<j(0<=j& ...

  7. 132. Palindrome Partitioning II (String; DP)

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

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

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

  9. Leetcode_1278. Palindrome Partitioning III_[DP]

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

随机推荐

  1. Android_Service详解及实例

    转自:http://blog.csdn.net/guolin_blog/article/details/11952435    http://blog.csdn.net/guolin_blog/art ...

  2. python 爬虫1 開始,先拿新浪微博開始

    刚刚開始学. 目的地是两个.一个微博,一个贴吧 存入的话,临时还没想那么多.先存到本地目录吧 分词和推荐后面在整合 mysql mongodb hadoop redius 后面在用 我最终知道为什么大 ...

  3. Mac使用小结

    1.修改pip的镜像地址及更新pip https://www.cnblogs.com/techroad4ca/p/5922389.html 2.更新python的库,比如更新six sudo pip ...

  4. 在Java中如何正确地终止一个线程

    1.使用Thread.stop()? 极力不推荐此方式,此函数不安全且已废弃,具体可参考Java API文档 2.设置终止标识,例如: import static java.lang.System.o ...

  5. VC FTP服务器程序分析(四)

    下面是数据传输的重点-CDataSocket类,函数不多,都比较重要. 1.OnAccept  数据tcp服务器被连接的虚函数,由框架调用. void CDataSocket::OnAccept(in ...

  6. JOptionPane常用提示框

    //JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon); JOptionPane.sho ...

  7. 微信公众号菜单与应用交互session

    http://www.cnblogs.com/yank/p/3476874.html http://blog.csdn.net/zmhawk/article/details/43671195 http ...

  8. 项目中Redis分库

    Redis中有16个库 默认第0个库 配置库的设置: 不同的库  key可以重复哈 公司的多个不同分布式项目,但是只有一个redis时候,以项目方式区分不同的库 每个项目连接相同 但是库不同

  9. xunit输出output到控制台

    1.https://xunit.github.io/docs/capturing-output 里面似乎提到2个方法,第二个方法还需要在配置文件中添加appSetting 这里采用第一种方法, 1.添 ...

  10. CodeForces19D:Points(线段树+set(动态查找每个点右上方的点))

    Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coo ...