D - Palindrome Partitioning (DP)
Description
A palindrome partition is the partitioning of a string such that each separate substring is a palindrome.
For example, the string "ABACABA" could be partitioned in several different ways, such as {"A","B","A","C","A","B","A"}, {"A","BACAB","A"}, {"ABA","C","ABA"}, or {"ABACABA"}, among others.
You are given a string s. Return the minimum possible number of substrings in a palindrome partition of s.
Input
Input starts with an integer T (≤ 40), denoting the number of test cases.
Each case begins with a non-empty string s of uppercase letters with length no more than 1000.
Output
For each case of input you have to print the case number and the desired result.
Sample Input
3
AAAA
ABCDEFGH
QWERTYTREWQWERT
Sample Output
Case 1: 1
Case 2: 8
Case 3: 5
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define N 2010000
char s[N];
int f[N],cnt=,t;
bool pdhw(int n,int m){
for(int i=n,j=m;i<=(n+m)/;i++,j--)
if(s[i]!=s[j]) return ; return ;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%s",s);
int len=strlen(s);
for(int i=;i<len;i++){
f[i]=i+;
for(int j=;j<=i;j++)
if(pdhw(j,i))
f[i]=min(f[i],f[j-]+);
}
printf("Case %d: %d\n",++cnt,f[len-]);
}
return ;
}
D - Palindrome Partitioning (DP)的更多相关文章
- Lightoj 1044 - Palindrome Partitioning (DP)
题目链接: Lightoj 1044 - Palindrome Partitioning 题目描述: 给一个字符串,问至少分割多少次?分割出来的子串都是回文串. 解题思路: 先把给定串的所有子串是不 ...
- Atcoder Yet Another Palindrome Partitioning(状压dp)
Atcoder Yet Another Palindrome Partitioning 思路: 一个字符串满足条件的情况是奇数字母个数小于等于1,也就是异或起来是1<<j(0<=j& ...
- 132. Palindrome Partitioning II (String; DP)
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 131. Palindrome Partitioning (Back-Track, DP)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- 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 ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Leetcode: Palindrome Partitioning II
参考:http://www.cppblog.com/wicbnu/archive/2013/03/18/198565.html 我太喜欢用dfs和回溯法了,但是这些暴力的方法加上剪枝之后复杂度依然是很 ...
随机推荐
- SCOM Visio监控 与sharepoint 2010 整合
激活sharepoint 2010的企业版网站功能 在sharepoint 前端服务器安装:OpsMgrDataModule.msi,安装好后可以看到如下东东: 在Sharepoint前端服务器中启动 ...
- C编程常见问题总结
本文是C编程中一些常见错误的总结,有些是显而易见的,有些则是不容易发现 本文地址:http://www.cnblogs.com/archimedes/p/get-screwed-c.html,转载请注 ...
- Android学习一(入门)
一.Android 系统简介 1.1.1G-4G 1G:模拟制式手机,1995年问世的第一代模拟制式手机,只能进行语音通话, 2G:手机使用GSM,CDMA(9K/s),增加了接收数据的功能 2.5G ...
- Spring中配置数据源的4种形式(转)
原文http://blog.csdn.net/orclight/article/details/8616103 不管采用何种持久化技术,都需要定义数据源.Spring中提供了4种不同形式的 ...
- IOS xib在tableview上的简单应用(通过xib自定义cell)
UITableView是一种常用的UI控件,在实际开发中,由于原生api的局限,自定义UITableViewCell十分重要,自定义cell可以通过代码,也可以通过xib. 这篇随笔介绍的是通过xib ...
- 小波说雨燕 第三季 构建 swift UI 之 度假清单 学习笔记
最终的效果: <1>第一个场景: 1.本地化 界面简体中文化 Supporting Files - info.plist Localization native development r ...
- QA:java.lang.RuntimeException:java.io.FileNotFoundException:Resource nexus-maven-repository-index.properties does not exist.
QA:java.lang.RuntimeException:java.io.FileNotFoundException:Resource nexus-maven-repository-index.pr ...
- (android) SharedPreferences 两种方式的存储范围
1 SharedPreferences settings =Activity.getPreferences(Activity.MODE_PRIVATE); 访问数据的范围为 当前的activity 2 ...
- linux配置文件的一些调优
Linux中所有东西都是文件,一个socket就对应着一个文件描述符,因此系统配置的最大打开文件数以及单个进程能够打开的最大文件数就决定了socket的数目上限:但是linux是有文件句柄限制的,而且 ...
- CityEngine Web Scene如何在IIS下部署 [转]
CityEngine2012新增了发布Web场景的功能,可以通过本地的Web Scene Viewer打开,也可以发布到ArcGIS Online云端进行共享.如下图: 注:3ws场景包制作方法: ...