区间DP UVA 11584 Partitioning by Palindromes
/*
题意:给一个字符串,划分成尽量少的回文串
区间DP:状态转移方程:dp[i] = min (dp[i], dp[j-1] + 1); dp[i] 表示前i个字符划分的最少回文串,
如果s[j] 到 s[i]是回文串,那么可以从dp[j-1] + 1递推过来
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
int dp[MAXN];
char s[MAXN]; bool ok(int l, int r) {
while (l < r) {
if (s[l] != s[r]) return false;
l++; r--;
}
return true;
} int main(void) { //UVA 11584 Partitioning by Palindromes
int T; scanf ("%d", &T);
while (T--) {
scanf ("%s", s + );
int len = strlen (s + );
memset (dp, , sizeof (dp));
for (int i=; i<=len; ++i) {
dp[i] = i;
for (int j=; j<=i; ++j) {
if (ok (j, i)) {
dp[i] = min (dp[i], dp[j-] + );
}
}
} printf ("%d\n", dp[len]);
} return ;
}
区间DP UVA 11584 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 线性dp
// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...
- UVA 11584 Partitioning by Palindromes (字符串区间dp)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 11584 - Partitioning by Palindromes DP
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 11584 Partitioning by Palindromes【DP】
题意:给出一个字符串,问最少能够划分成多少个回文串 dp[i]表示以第i个字母结束最少能够划分成的回文串的个数 dp[i]=min(dp[i],dp[j]+1)(如果从第j个字母到第i个字母是回文串) ...
- UVa 11584 - Partitioning by Palindromes(线性DP + 预处理)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 11584 Partitioning by Palindromes (简单DP)
题意:给定一个字符串,求出它最少可分成几个回文串. 析:dp[i] 表示前 i 个字符最少可分成几个回文串,dp[i] = min{ 1 + dp[j-1] | j-i是回文}. 代码如下: #pra ...
- UVA 11584 "Partitioning by Palindromes"(DP+Manacher)
传送门 •题意 •思路一 定义 dp[i] 表示 0~i 的最少划分数: 首先,用马拉车算法求解出回文半径数组: 对于第 i 个字符 si,遍历 j (0 ≤ j < i),判断以 j 为回文中 ...
- UVA - 11584 Partitioning by Palindromes(划分成回文串)(dp)
题意:输入一个由小写字母组成的字符串,你的任务是把它划分成尽量少的回文串,字符串长度不超过1000. 分析: 1.dp[i]为字符0~i划分成的最小回文串的个数. 2.dp[j] = Min(dp[j ...
随机推荐
- org.osgi.framework.BundleException: Exception in org.eclipse.core.resources.ResourcesPlugin.start()
http://freestyle21.cn 不知什么时候,启动eclipse的时候就一直不行,说是an error ..我查了下log 报错:org.osgi.framework.BundleExce ...
- csu - 1566: The Maze Makers (bfs)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1566 题意还是蛮难懂的,至少对于我来说,需要认真读题. 输入矩阵的每一个数字换成2进制后,顺时针围 ...
- nyoj_176_队花的烦恼二_201404262008
队花的烦恼二 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 ACM队队花C小+最近在X大OJ上做题,竟发现了一道做不出来的…水题!她快郁闷死了……也许是最近状态不太 ...
- P1028 数的计算 洛谷
https://www.luogu.org/problem/show?pid=1028 题目描述 我们要求找出具有下列性质数的个数(包含输入的自然数n): 先输入一个自然数n(n<=1000), ...
- eclipse断点有个斜杠 skip all breakpoints
切换到debug,单击下 skip all breakpoints 即可
- 【CV论文阅读】+【搬运工】LocNet: Improving Localization Accuracy for Object Detection + A Theoretical analysis of feature pooling in Visual Recognition
论文的关注点在于如何提高bounding box的定位,使用的是概率的预测形式,模型的基础是region proposal.论文提出一个locNet的深度网络,不在依赖于回归方程.论文中提到locne ...
- 踩坑录- Spring Boot - CORS 跨域 - 浏览器同源策略
1.解决办法,创建一个过滤器,处理所有response响应头 import java.io.IOException; import javax.servlet.Filter; import javax ...
- bootstrap 时间控件
近期使用了bootstrap的UI感觉确实非常美丽,非常值得学习和使用. 以下先简单了解下bootstrap的时间控件. 这个时间控件使用起来还是很的简单.仅仅须要引入主要的css和js就能够了 须要 ...
- [Python] How to unpack and pack collection in Python?
It is a pity that i can not add the video here. As a result, i offer the link as below: How to unpa ...
- u
Atrrible /s/d –s –h u盘修复