Lightoj 1044 - Palindrome Partitioning (DP)
题目链接:
Lightoj 1044 - Palindrome Partitioning
题目描述:
给一个字符串,问至少分割多少次?分割出来的子串都是回文串。
解题思路:
先把给定串的所有子串是不是回文串处理出来,然后用dp[i] 表示 从起点到串i的位置的最少分割次数,然后结合处理出来的回文串转移一下即可!
还是好蠢哦!自己竟然感觉是一个区间DP,但是n又那么大,完全不是区间DP的作风啊!
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std;
typedef long long LL;
const int maxn = ;
const int INF = 0x3f3f3f3f; int dp[maxn];
bool a[maxn][maxn];
char str[maxn];
int main ()
{
int T;
scanf ("%d", &T);
for (int t=; t<=T; t++)
{
scanf ("%s", str+);
memset(a, false, sizeof(a));
int len = strlen (str+); for (int i=; str[i]; i++)
a[i][i] = true; for (int i=; i<=len; i++)
for (int l=; l+i<=len+; l++)
{
int r = l + i - ;
if ((r == l + || a[l+][r-]) && str[l] == str[r]) a[l][r] = true;
else a[l][r] = false;
} dp[] = ;
for (int i=; i<=len; i++)
{
dp[i] = INF;
for (int j=; j<=i; j++)
if (a[j][i]) dp[i] = min (dp[i], dp[j-]+);
}
printf ("Case %d: %d\n", t, dp[len]);
}
return ;
}
Lightoj 1044 - Palindrome Partitioning (DP)的更多相关文章
- LightOJ 1044 Palindrome Partitioning(简单字符串DP)
A palindrome partition is the partitioning of a string such that each separate substring is a palind ...
- lightoj 1044 - Palindrome Partitioning(需要优化的区间dp)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 题意:求给出的字符串最少能分成多少串回文串. 一般会想到用区间dp暴力3个for ...
- Light oj 1044 - Palindrome Partitioning(区间dp)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 dp[i][j]表示i到j直接的最小回文区间个数,直接看代码 #include ...
- 1044 - Palindrome Partitioning(区间DP)
题目大意: 给你一个字符串,问这个字符串最少有多少个回文串. 区间DP直接搞 #include<cstdio> #include<cstring> #include&l ...
- D - Palindrome Partitioning (DP)
Description A palindrome partition is the partitioning of a string such that each separate substring ...
- 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 ...
随机推荐
- JAVA WEB学习笔记(三):简单的基于Tomcat的Web页面
注意:每次对Tomcat配置文件进行修改后,必须重启Tomcat 在E盘的DATA文件夹中创建TomcatDemo文件夹,并将Tomcat安装路径下的webapps/ROOT中的WEB-INF文件夹复 ...
- label 对齐
<label for="username">用户名</label> <input type="text" id="use ...
- LeetCode 112 Path Sum(路径和)(BT、DP)(*)
翻译 给定一个二叉树root和一个和sum, 决定这个树是否存在一条从根到叶子的路径使得沿路全部节点的和等于给定的sum. 比如: 给定例如以下二叉树和sum=22. 5 / \ 4 8 / / \ ...
- iOS优秀博文合集
一.优化篇 Xcode7中你一定要知道的炸裂调试神技 iOS使用Instrument-Time Profiler工具分析和优化性能问题 dSYM 文件分析工具 二.功能篇 3分钟实现iOS语言本地化/ ...
- 对云资源服务商资源读写的架构思考:前端代码走token
第一.统一了访问端接口.提高前端开发速度:第二统一了阿里各个产品的 数据读写模式: 第三,我们的服务器产生token时对读写规则做限制,特定的token由特定的规则产生,而不是让前端代代码去管控限制 ...
- C++文件IO操作的简单示例
CppIODemo1.cpp #include <iostream> #include <fstream> #include <chrono> #define IN ...
- Windows 7 繁体中文MSDN原版
Win7 SP1 64位旗舰版繁体版ISO镜像(香港):文件名:hk_windows_7_enterprise_with_sp1_x64_dvd_620688.isoSHA1:82D59B099333 ...
- android adb 源码框架分析(2 角色)【转】
本文转载自:http://blog.csdn.net/luansxx/article/details/25203323 角色 l 服务 服务是提供特定功能的实体,接收请求,返回应答是服务直接最表现. ...
- 如何修改织梦dedecms文章标题的最大长度
织梦dedecms默认的文章标题的最大长度为60字节,如果文章标题超过60字节将会自动截断,导致标题显示不全,这并非是我们所希望的.那么如何将标题长度改成我们想要的?只需简单两步即可解决问题. 1.进 ...
- Java中的Lock
同步机制是Java并发编程中最重要的机制之一,锁是用来控制多个线程访问共享资源的方式,一般来说,一个锁能防止多个线程同时访问共享资源(但是也有例外,比如读写锁).Java中可以使用synchroniz ...