Partitioning by Palindromes
题意:
给定一个字符串,求能分成最小几个回文串
分析:简单dp dp[i]前i个字符能分成的最小数量 dp[i]=min(dp[i],dp[j-1]+1) (j-i 是回文串)
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int dp[];
char s[];
int judge(int x,int y){
while(x<y){
if(s[x]!=s[y])return ;
x++;y--;
}
return ;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%s",(s+));
int len=strlen(s+);
for(int i=;i<=len;++i)
dp[i]=INF;
dp[]=;
for(int i=;i<=len;++i)
for(int j=;j<=i;++j)
if(judge(j,i)){
dp[i]=min(dp[i],dp[j-]+);
}
printf("%d\n",dp[len]);
}
return ;
}
Partitioning by Palindromes的更多相关文章
- 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 ...
- UVa 11584 Partitioning by Palindromes
题意: 给出一个字符串,求最少能划分成多少个回文子串. 分析: d[i] = min{d[j] + 1 | s[j+1]...s[i]是回文串} d[i]表示前 i 个字符最少能分割的回文子串的个数 ...
- UVa 11584 Partitioning by Palindromes【DP】
题意:给出一个字符串,问最少能够划分成多少个回文串 dp[i]表示以第i个字母结束最少能够划分成的回文串的个数 dp[i]=min(dp[i],dp[j]+1)(如果从第j个字母到第i个字母是回文串) ...
- 【线性结构上的动态规划】UVa 11584 - Partitioning by Palindromes
回文串问题.给出一个字符串,问最少可以划分为多少个字符串子串. 对于判断是否为回文串,对于不是很长的字符串,可以采取直接暴力,即从两边向中间收缩判断字符相等. bool is_pali(int l, ...
- UVa11584 - Partitioning by Palindromes(区间DP)
题目大意 给定一个小写字母组成的字符串S,你的任务是划分成尽量少的回文串 题解 方程就是dp[j]=min(dp[i-1]+1)(i<=j,s[i..j]是回文串) 代码: #include&l ...
随机推荐
- Nodejs常见安装
1.Windows 下成功安装node-canvas2.jsdom——node.js的DOM
- 空格的URL编码
Q: 为什么我看的教材一会说是“+” 一会说是“%20” A: urlencode(" ") '返回+encodeURI(" ") '返回%20是有区别的
- Git PHP提交
做了个小的DEMO,可以查看: https://github.com/feixiang/webgit.git 这几天一直在郁闷的事情. Git在shell里面执行得好好的,apache运行用户也改成了 ...
- FFMpeg那些事——独立运行的二进制文件ffmpeg编译
想编译一个Android可用的二进制文件(要求:支持libx264/liblamemp3) github资源: 1.首先编译一个带lame库的ffmpeg https://github.com/aks ...
- lintcode :Trailing Zeros 尾部的零
题目: 尾部的零 设计一个算法,计算出n阶乘中尾部零的个数 样例 11! = 39916800,因此应该返回 2 挑战 O(logN)的时间复杂度 解题: 常用方法: 也许你在编程之美中看到,通过求能 ...
- 248. Strobogrammatic Number III
题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...
- hadoop-0.23.9安装以及第一个mapreduce测试程序
hadoop是一个能够对大量数据进行分布式处理的软件框架.它实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS.HDFS有着高容错性的特点,并且设计 ...
- 车牌识别LPR(八)-- 字符识别
第八篇:字符识别 车牌定位.车牌倾斜校正.车牌字符分割都是为车牌字符识别做的前提工作,这些前提工作直接关系到车牌识别系统的性能.车牌字符识别是车牌识别系统的核心部分,车牌字符识别的准确率是衡量车牌识 ...
- ExtJs自学教程(2):从DOM看EXTJS
<二> 从DOM看EXTJS 看标题可能有人会问,为啥好好的例子不看,得从DOM看起呢?答案是目标只为了一个:自运行结果把EXTJS看得更清楚点 首先,要看得靠点工具,带点放大镜什么吧?对 ...
- gulp.watch监听文件
Gulp.watch()会返回我们熟知的watcher.我们可以利用watcher来监听额外的事件或者向watch中添加文件. 例如,在执行一系列任务和调用一个函数时,你就可以在返回的watcher中 ...