uva 11584 - 字符串 dp
一个长度1000的字符串最少划分为几个回文字符串
-----------------------------------------------------------------------------------------------------------------
想复杂了。
首先N2的时间预处理一下,从i开始长度为len的字符串是否为回文串。
dist(i) = MIN(dist(i),dist(j)+1) 如果 j-i 为一个回文串
- #include <set>
- #include <map>
- #include <stack>
- #include <queue>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <iostream>
- #include <algorithm>
- #define MAX(a,b) ((a)>=(b)?(a):(b))
- #define MIN(a,b) ((a)<=(b)?(a):(b))
- #define OO 0x0fffffff
- using namespace std;
- typedef long long LL;
- const int N = ;
- bool dp[N][N];
- int minDist[N];
- char str[N];
- int main(){
- int n; for(cin>>n;n--;){
- scanf("%s",str); int length = strlen(str);
- for(int i=;i<length;i++) minDist[i] = i+;
- memset(dp,false,sizeof(dp));
- for(int len=;len<;len++) for(int i=;i<length;i++) {
- dp[len][i]=true;
- }
- for(int len=;len<=length;len++){
- for(int i=;i<length;i++){
- if(len+i>length) break;
- dp[len][i] = (str[i]==str[i+len-])&&(dp[len-][i+]);
- }
- }
- for(int i=;i<length;i++){
- for(int j=;j<=i;j++){
- if(dp[i-j+][j]) minDist[i] = MIN(minDist[i],j?(minDist[j-]+):);
- }
- }
- printf("%d\n",minDist[length-]);
- }
- return ;
- }
- /*
- 3
- racecar
- fastcar
- aaadbccb
- */
uva 11584 - 字符串 dp的更多相关文章
- Partitioning by Palindromes UVA - 11584 简单dp
题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...
- UVA 11584 入门DP
一开始把它当成暴力来做了,即,从终点开始,枚举其最长的回文串,一旦是最长的,马上就ans++,再计算另外的部分...结果WA了 事实证明就是一个简单DP,算出两个两个点组成的线段是否为回文,再用LCS ...
- UVA - 11584 划分字符串的回文串子串; 简单dp
/** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单 ...
- 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]
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.10192 Vacation (DP LCS)
UVA.10192 Vacation (DP LCS) 题意分析 某人要指定旅游路线,父母分别给出了一系列城市的旅游顺序,求满足父母建议的最大的城市数量是多少. 对于父母的建议分别作为2个子串,对其做 ...
- 【BZOJ 2121】 (字符串DP,区间DP)
2121: 字符串游戏 Description BX正在进行一个字符串游戏,他手上有一个字符串L,以及其他一些字符串的集合S,然后他可以进行以下操作:对于一个在集合S中的字符串p,如果p在L中出现,B ...
随机推荐
- 三种启动SQLSERVER服务的方法(启动sqlserver服务器,先要启动sqlserver服务)
1.后台启动 计算机-管理-服务和应用程序 2.SQL SERVER配置管理器 3.在运行窗口中使用命令进行启动:
- Sqlite基本命令集合(linux/fedora/ubuntu)
注:fedora自带sqlite3,无需安装,直接输入命令sqlite3即可. ------------Ubuntu在命令行输入sqlite3,确认没有安装在进行--- 1.安装sqlite3 ubu ...
- Linux常见后缀缩写含义
ctl: control rc: run control (A run-control file is a file of declarations or commands associated wi ...
- Unity 动画系统(Mecanim) 术语及翻译 表格
原文 翻译 Animation Clip 视频片段 Avatar 阿凡达 Retargeting 重定向 Rigging 绑定 skinning 蒙皮 Animator Component 动画组件 ...
- vue 中判断向上滚动还是向下滚动
<script> export default { data(){ return{ i = 0 } }, mounted () { window.addEventListener('scr ...
- Pyhton学习——Day29
#异常与错误# 什么是异常?# 异常就是程序运行时发生错误的信号,在程序出现错误时,则会产生异常,若没有程序处理,则会抛出异常# 导致程序在异常语句处崩溃终止# Traceback 追踪异常信号:** ...
- Web API Filter
在Web Api中,有三种Filter Filter类型 实现的接口 描述 Authorization IAuthorizationFilter 最先运行的Filter,被用作请求权限校验 Actio ...
- java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
最近在使用java PiO导入导出Excle在windos本机上运行没有问题: 但是!!问题来了!放到Linux服务器上部署后出现异常 java.lang.NoClassDefFoundError: ...
- jquery 用于操作动态元素的delegate/on方法
delegate() 方法的事件处理程序适用于当前或未来的元素(比如由脚本创建的新元素). 在做项目中有很多由ajax动态生成的html标签,jquery对这些标签不会响应\((selector).c ...
- [LeetCode] 350. 两个数组的交集 II intersection-of-two-arrays-ii(排序)
思路: 先找到set的交集,然后分别计算交集中的每个元素在两个原始数组中出现的最小次数. class Solution(object): def intersect(self, nums1, nums ...