1044 - Palindrome Partitioning(区间DP)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int MAXN = ;
int dp[MAXN][MAXN];
bool P[MAXN][MAXN];
char str[MAXN];
int DFS(int L,int R)
{
if(dp[L][R] != -)
return dp[L][R];
if(L >= R)
return dp[L][R] = ; dp[L][R] = INF;
if(P[L][R]) dp[L][R] = ;
for(int i=L; i<=R; i++)
{
if(P[L][i])
dp[L][R] = min(dp[L][R], + DFS(i+,R));
}
return dp[L][R];
} bool ok(int L,int R)
{
for(int i=L,j=R; i<=j; i++, j--)
{
if(str[i] != str[j])
return false;
}
return true;
} int main()
{
int T, cas = ;
scanf("%d", &T);
while(T --)
{
memset(dp, -, sizeof(dp));
scanf("%s", str);
int len = strlen(str) - ;
for(int i=; i<=len; i++)
for(int j=i; j<=len; j++)
P[i][j] = ok(i, j); printf("Case %d: %d\n",cas ++, DFS(, len) );
} return ;
}
1044 - Palindrome Partitioning(区间DP)的更多相关文章
- Lightoj 1044 - Palindrome Partitioning (DP)
题目链接: Lightoj 1044 - Palindrome Partitioning 题目描述: 给一个字符串,问至少分割多少次?分割出来的子串都是回文串. 解题思路: 先把给定串的所有子串是不 ...
- lightoj 1044 - Palindrome Partitioning(需要优化的区间dp)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 题意:求给出的字符串最少能分成多少串回文串. 一般会想到用区间dp暴力3个for ...
- HDU4632:Palindrome subsequence(区间DP)
Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...
- 131. Palindrome Partitioning (Back-Track, DP)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Cheapest Palindrome(区间DP)
个人心得:动态规划真的是够烦人的,这题好不容易写出了转移方程,结果超时,然后看题解,为什么这些题目都是这样一步一步的 递推,在我看来就是懵逼的状态,还有那个背包也是,硬是从最大的V一直到0,而这个就是 ...
- Leetcode_1278. Palindrome Partitioning III_[DP]
题目链接 You are given a string s containing lowercase letters and an integer k. You need to : First, ch ...
- Leetcode_132. Palindrome Partitioning II_[DP]
题目链接 Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...
- HDU 4632 Palindrome subsequence(区间dp,回文串,字符处理)
题目 参考自博客:http://blog.csdn.net/u011498819/article/details/38356675 题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. ...
- HDU 4632 Palindrome subsequence (区间DP)
题意 给定一个字符串,问有多少个回文子串(两个子串可以一样). 思路 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字符串中[i,j]位置中出现的回文子序 ...
随机推荐
- Using native GDI for text rendering in C#
Using native GDI for text rendering in C# Aug12by Arthur To complete my previous post on text render ...
- MySQL使用指南(上)
作者:大金刚 有很多朋友虽然安装好了mysql但却不知如何使用它.在这篇文章中我们就从连接MYSQL.修改密码.增加用户等方面来学习一些MYSQL的常用命令. 一.连接MYSQL. 格式: mys ...
- java Junit 测试中异常处理
错误提示: junit.framework.AssertionFailedError: No tests found in错误解决办法 用junit Test运行后,出现如下的错误:junit.fra ...
- html-----002
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- WPF中TreeView数据结构解析
XAML.CS代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- Django练习项目之搭建博客
背景:自从今年回家过年后,来到公司给我转了试用,我的学习效率感觉不如从前,而且刚步入社会我总是想要怎么想明白想清楚一些事,这通常会花掉,消耗我大量的精力,因为我想把我的生活管理规划好了,而在it技术学 ...
- CSS3中的选择器
首先, CSS即层叠样式表(Cascading StyleSheet) CSS3是CSS技术的升级版本,CSS3语言开发是朝着模块化发展的 模块包括: 盒子模型.列表模块.超链接方式 .语言模块 .背 ...
- Convention插件与“约定”支持
主要用于Action映射和Result映射 struts2-convention-plugin-2.3.16.3.jar 会将 |--实现了com.opensymphony.xwork2.Action ...
- Ext.Date 方法
1.Ext.Date.add(date,interval,value); 提供执行基本日期运算的简便方法; date 日期对象, interval 一个有效的日期间隔枚举值, value 向当前日期上 ...
- 2016022607 - redis配置文件
在Redis有配置文件(redis.conf)可在Redis的根目录下找到.可以通过Redis的CONFIG命令设置所有Redis的配置. Redis的CONFIG命令的基本语法如下所示: redis ...