题目链接:

  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. html使用代码大全

    <DIV style="FONT-SIZE: 9pt">1)贴图:<img src="图片地址">1)首行缩进2格:<p styl ...

  2. LeetCode(38)题解: Count and Say

    https://leetcode.com/problems/count-and-say/ 题目: The count-and-say sequence is the sequence of integ ...

  3. 赵雅智_SimpleCursorAdapter

    项目步骤 声明listView控件并获取显示的视图 获取显示的数据 设置显示的adapter 注冊点击事件 详细案例 实现效果: watermark/2/text/aHR0cDovL2Jsb2cuY3 ...

  4. java zip压缩优化版 解决压缩后文件一直被占用无法删除

    最近进行zip操作,从网上找到一个处理方法,但是经过试验存在一些bug,主要是文件流的申明存在问题,导致jvm一直占用文件而不释放,特意把自己修改的发出来,已备记录 import java.io.Bu ...

  5. How MySQL Opens and Closes Tables refuse connections 拒绝连接的原因 file descriptors

    MySQL :: MySQL 5.7 Reference Manual :: 8.4.3.1 How MySQL Opens and Closes Tables https://dev.mysql.c ...

  6. 【翻译自mos文章】即使resource_limit = false, password的 资源限制也会生效

    即使resource_limit = false, password的 资源限制也会生效 參考原文: Resource limits for passwords work even with reso ...

  7. i MySQL 查看约束,添加约束,删除约束

    查看表的字段信息:desc 表名; 查看表的所有信息:show create table 表名; 添加主键约束:alter table 表名 add constraint 主键 (形如:PK_表名) ...

  8. js-easyUI格式化时间

    formatter : function(value, row) { if(value != null){ var date = new Date(value); var y = date.getFu ...

  9. hihocoder 1082 然而沼跃鱼早就看穿了一切 (替换指定的串 )

    #1082 : 然而沼跃鱼早就看穿了一切 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句 ...

  10. SDUT 3035 你猜我猜不猜你猜不猜(字符串 规律性)

    你猜我猜不猜你猜不猜 Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In the past 39th annual ACM in ...