Lightoj 1044 - Palindrome Partitioning (DP)
题目链接:
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)的更多相关文章
- LightOJ 1044 Palindrome Partitioning(简单字符串DP)
A palindrome partition is the partitioning of a string such that each separate substring is a palind ...
- lightoj 1044 - Palindrome Partitioning(需要优化的区间dp)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 题意:求给出的字符串最少能分成多少串回文串. 一般会想到用区间dp暴力3个for ...
- Light oj 1044 - Palindrome Partitioning(区间dp)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 dp[i][j]表示i到j直接的最小回文区间个数,直接看代码 #include ...
- 1044 - Palindrome Partitioning(区间DP)
题目大意: 给你一个字符串,问这个字符串最少有多少个回文串. 区间DP直接搞 #include<cstdio> #include<cstring> #include&l ...
- D - Palindrome Partitioning (DP)
Description A palindrome partition is the partitioning of a string such that each separate substring ...
- Atcoder Yet Another Palindrome Partitioning(状压dp)
Atcoder Yet Another Palindrome Partitioning 思路: 一个字符串满足条件的情况是奇数字母个数小于等于1,也就是异或起来是1<<j(0<=j& ...
- 132. Palindrome Partitioning II (String; DP)
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 131. Palindrome Partitioning (Back-Track, DP)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Leetcode_1278. Palindrome Partitioning III_[DP]
题目链接 You are given a string s containing lowercase letters and an integer k. You need to : First, ch ...
随机推荐
- JAVA WEB学习笔记(二):Tomcat服务器的安装及配置
一.Tomcat的下载及安装. 前往Tomcat官网下载安装包或者免安装压缩包.链接http://tomcat.apache.org/ 这里,我选择的是Tomcat8.0,而不是最新的Tomcat9. ...
- 设计模式学习笔记——Mediator中介者模式
将众多对象之间的网状关系转为全部通过一个中间对象间接发生关系,此中间对象为中介者. 看图最直观: 作用不言而喻,就是降低对象之间的耦合度,乃至降低了整个系统的复杂度. 有点象代理模式,更象外观模式:
- 4408: [Fjoi 2016]神秘数
4408: [Fjoi 2016]神秘数 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 452 Solved: 273 [Submit][Stat ...
- ExtJs4.2 开发问题总结
1. 在开发treegrid中,store属性autoLoad:false没有作用,还会默认自动加载.目前解决办法在control下监听treegrid的afterrender,当加载完后,再调一次s ...
- 使用Mock.js进行独立于后端的前端开发
Mockjs能做什么? 基于 数据模板 生成模拟数据. 基于 HTML模板 生成模拟数据. 拦截并模拟 ajax 请求. 能解决的问题 开发时,前后端进度不同步,后端还没完成数据输出,前端只好写静态模 ...
- swift的String处理
import UIKit import CoreText class ViewController: UIViewController { override func viewDidLoad() { ...
- 更改NavigationView侧滑菜单文字颜色
NavigationView menu默认icon和title会随着菜单状态改变而改变,选择某个菜单后再次打开侧边菜单后会发现该菜单的icon和title会变成应用的主颜色,其他菜单项仍然为黑色. 如 ...
- 一步一步学Silverlight 2系列(22):在Silverlight中如何用JavaScript调用.NET代码
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- WAS:修改jsp编译器用JDK5.0
问题现象: 今天有现场反映,访问应用的个别页面报错,报错内容如下: 于是先查看其他现场,都是好的:根据报错信息,提示的意思是jsp解析不了. 结合上面2个情况,排除代码问题,应该是现场WAS环境问 ...
- node npm 总结
是nodejs的软件包管理器,用于node插件管理 npm install <name> [-g] [--save -dev] name:安装模块的名称 -g:全局安装 --save:将保 ...