uva11584 Partitioning by Palindromes
题目大意:
给出一个字符串,把他划分成尽量少的回文串,问最少的回文串个数
/*
先预处理所有回文子串
dp[i]表示字符1~i划分成的最小回文串的个数
*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int t,dp[];
char s[];
bool p[][];
int main(){
//freopen("Cola.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%s",s+);
int len=strlen(s+);
memset(p,,sizeof(p));
memset(dp,/,sizeof(dp));
for(int i=;i<=len;i++){
int l=i,r=i;
p[i][i]=;
while(l>&&r<len){
l--;r++;
if(s[l]==s[r]){
p[l][r]=p[r][l]=; }
else break;
}
l=i+;r=i;
while(l>&&r<len){
l--;r++;
if(s[l]==s[r]){
p[l][r]=p[r][l]=;
}
else break;
}
}
dp[]=;dp[]=;
for(int i=;i<=len;i++){
for(int j=;j<i;j++){
if(p[j+][i]){
dp[i]=min(dp[i],dp[j]+);
}
}
}
printf("%d\n",dp[len]);
}
}
uva11584 Partitioning by Palindromes的更多相关文章
- 【题解】UVA11584 Partitioning by Palindromes
UVA11584 https://www.luogu.org/problemnew/show/UVA11584 暑假开始刷lrj紫/蓝书DP题 这几天做的一道 思路 预处理出所有的回文串是否存在 前提 ...
- UVA-11584 Partitioning by Palindromes 动态规划 回文串的最少个数
题目链接:https://cn.vjudge.net/problem/UVA-11584 题意 给一个字符串序列,问回文串的最少个数. 例:aaadbccb 分为aaa, d, bccb三份 n< ...
- UVa11584 - Partitioning by Palindromes(区间DP)
题目大意 给定一个小写字母组成的字符串S,你的任务是划分成尽量少的回文串 题解 方程就是dp[j]=min(dp[i-1]+1)(i<=j,s[i..j]是回文串) 代码: #include&l ...
- UVA-11584 Partitioning by Palindromes (简单线性DP)
题目大意:给一个全是小写字母的字符串,判断最少可分为几个回文子序列.如:“aaadbccb” 最少能分为 “aaa” “d” “bccb” 共三个回文子序列,又如 “aaa” 最少能分为 1 个回文子 ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
- UVA 11584 一 Partitioning by Palindromes
Partitioning by Palindromes Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %l ...
- uva 11584 Partitioning by Palindromes 线性dp
// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...
- 区间DP UVA 11584 Partitioning by Palindromes
题目传送门 /* 题意:给一个字符串,划分成尽量少的回文串 区间DP:状态转移方程:dp[i] = min (dp[i], dp[j-1] + 1); dp[i] 表示前i个字符划分的最少回文串, 如 ...
- UVA-11584:Partitioning by Palindromes(基础DP)
今天带来一个简单的线性结构上的DP,与上次的照明系统(UVA11400)是同一种类型题,便于大家类比.总结.理解,但难度上降低了. We say a sequence of characters is ...
随机推荐
- IOS UITableView reload 刷新某一个cell 或 section
通常刷新整个列表 我们都使用[self.tableView reloadData]; 有的时候,有变化更新的只是某一行 row 或者是某个section 所以只更新这一行就好了 //一个section ...
- [egret+pomelo]实时游戏杂记(3)
[egret+pomelo]学习笔记(1) [egret+pomelo]学习笔记(2) [egret+pomelo]学习笔记(3) 服务端的请求流程走完了一遍,下面就该看一下,在目前的服务端中,各服务 ...
- struts + hibernate笔记
1.hibernate: 1) Restrictions.eq 判断是否相等== (场景:一个类A中的属性t,这个属性t是另一个类B中的ID,找出输入为这个属性t的所有类A) tasks = ses ...
- 分布式任务调度平台XXL-Job搭建
下载: https://github.com/xuxueli/xxl-job 下载 然后倒入到自己的工程里面 引入后: 导入数据:跑一边 导入: 修改: Window -->show view- ...
- android使用mina需要注意的问题
1.第三方jar包的使用 如果在Java Build Path中使用Add External JARs这种方式,运行时会有找不到类的错误(我的上面有,如果你没出现,恭喜你),上网查了几种方 ...
- SpringMVC框架<mvc:default-servlet-handler/>的作用
1.创建一个新工程 Eclipse下新建一个web项目,File>New>Dynamic Web Project 2.添加Jar包 3.配置Web.xml 4.配置 ...
- Git_学习_02_ 分支
Git鼓励大量使用分支: 1.查看分支:git branch 2.创建分支:git branch <name> 3.切换分支:git checkout <name> 4.创建+ ...
- less语言特性
作为CSS的一种扩展,LESSCSS不仅向下兼容CSS的语法,而且连新增的特性也是使用CSS的语法.这样的设计使得学习LESS很轻松,而且你可以在任何时候回退到CSS. 变量 很容易理解: @nice ...
- ACM学习历程—POJ1151 Atlantis(扫描线 && 线段树)
Description There are several ancient Greek texts that contain descriptions of the fabled island Atl ...
- Codefoeces 734F. Anton and School 数学
Codefoeces 734F 题目大意: 给定两个正整数序列\(b,c\)构造一个正整数序列\(a\)使其满足 \[ \left\{ \begin{array}{} b_i=(a_i\text{ a ...