LightOJ1025 The Specials Menu(区间DP)
给一个字符串,问有几种删字符的方式使删后的非空字符串是个回文串。
当然区间DP:dp[i][j]表示子串stri...strj的方案数
感觉不好转移,可能重复算了。我手算了"AAA"这个数据,然后就搞出转移的方式:
d[i][j] = ∑ d[i'][j']+1 (i<=i'<=j'<=j 且 str[i']==str[j'])
这个区间DP和经典例题相邻石子合并一样,枚举长度然后枚举起点,这样保证计算过程的拓扑有序。时间复杂度O(strlen4)。
#include<cstdio>
#include<cstring>
using namespace std;
char str[];
long long d[][];
int main(){
int t;
scanf("%d",&t);
for(int cse=; cse<=t; ++cse){
scanf("%s",str);
int n=strlen(str);
memset(d,,sizeof(d));
for(int len=; len<=n; ++len){
for(int k=; k+len<=n; ++k){
d[k][k+len-]=len;
for(int i=; i<len; ++i){
for(int j=i+; j<len; ++j){
if(str[k+i]!=str[k+j]) continue;
d[k][k+len-]+=d[k+i+][k+j-]+;
}
}
}
}
printf("Case %d: %lld\n",cse,d[][n-]);
}
return ;
}
LightOJ1025 The Specials Menu(区间DP)的更多相关文章
- Lightoj 1025 - The Specials Menu (区间DP)
题目链接: Lightoj 1025 - The Specials Menu 题目描述: 给出一个字符串,可以任意删除位置的字符,也可以删除任意多个.问能组成多少个回文串? 解题思路: 自从开始学dp ...
- 【lightoj-1025】The Specials Menu(区间DP)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1025 [题目大意] 求一个字符串删去任意字符可以构成多少个不同的回文串 [分析 ...
- The Specials Menu LightOJ - 1025
The Specials Menu LightOJ - 1025 题意:在给定的字符串中删去一些字符,使其成为回文串(不能全部都删).求方案数. 方法:常规的区间dp.ans[i][j]表示在i到j的 ...
- 1025 - The Specials Menu
1025 - The Specials Menu PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
随机推荐
- UIImage 和 iOS 图片压缩UIImage / UIImageVIew
UIImageView 制作气泡 stretchableImageWithLeftCapWidth http://blog.csdn.net/justinjing0612/article/detail ...
- magic-encoding
(文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 今天页面跳转都出问题了,各种方法都试过了, log里说语法错误,问了pp,他说是汉字的原因...果 ...
- #define 和typedef的区别
typedef和define的详细区别 2011-04-19 15:11 firnow firnow 字号:T | T 对于都可以用来给对象取一个别名的Typedef和define来说,是有区别的.本 ...
- CentOS6 下安装HP-LaserJet 1020打印机
因为实验室有个多余的老服务器,所以近段时间想把老服务器做成打印机服务器,同时因为最近在学习linux,所以就像在CentOS6.3 上安装打印机驱动.因为是新手,所以走了不少弯路,今天终于把打印机安装 ...
- 栈应用hanoi
/* 课本p54页*/ #include<stdio.h> #include <iostream> using namespace std; void move(int n, ...
- poj1094 拓扑 Sorting It All Out
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29744 Accepted: 10 ...
- doTjs源码研究笔记
首先是入口方法 /*tmpl:模板文本 c:用户自定义配置 def:定义编译时执行的数据*/doT.template = function(tmpl, c, def) { } 然后进入第一句代码 c ...
- Linux下配置Hadoop 1.2.1
首先要下载hadoop的包,版本选择1.2.1的,下载地址为:http://mirrors.cnnic.cn/apache/hadoop/common/hadoop-1.2.1/ 这里可以下载hado ...
- TokuDB的特点验证
随着数据量越来越大,越来越频繁的遇到需要进行结构拆分的情况,每一次拆分都耗时很久,并且需要多方配合,非常的不想搞这个事情.于是在@zolker的提醒下想到了13年开源tokuDB,来解决我们迫在眉睫的 ...
- Java for LeetCode 149 Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...