hdu 4632 回文子序列计数
水题
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#define mod 10007
using namespace std;
char str[]; int dp[][],cas;
void work( )
{
int len = strlen( str );
memset( dp,,sizeof(dp) );
for( int i = ; i < len; i++ )dp[i][i] = ;
for( int i = ; i < len; i++ )
for( int j = ; j + i < len; j++ )
{
int t = i+j;
dp[j][t] = dp[j][t-] + dp[j+][t]; if( j+ <= t- ) dp[j][t] -= dp[j+][t-];
if( str[j] == str[t] )
{
if( j+ <= t- ) dp[j][t] += dp[j+][t-] + ;
else dp[j][t]++;
}
dp[j][t] %= mod; dp[j][t] += mod;
}
dp[][len-] %= mod;
printf("Case %d: %d\n",cas++,dp[][len-]);
}
int main( )
{
int T; cas = ;scanf("%d",&T);
while( T-- ){
scanf("%s",&str);work( );
}
return ;
}
hdu 4632 回文子序列计数的更多相关文章
- hdu-4632 Palindrome subsequence (回文子序列计数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 问题要求回答一串字符串中回文子序列的数量,例如acbca就有 a,c,b,c,a,cc,aa,a ...
- HDU 4632 Palindrome subsequence(区间DP求回文子序列数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题目大意:给你若干个字符串,回答每个字符串有多少个回文子序列(可以不连续的子串).解题思路: 设 ...
- [LeetCode] Count Different Palindromic Subsequences 计数不同的回文子序列的个数
Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...
- HDU 4745 Two Rabbits ★(最长回文子序列:区间DP)
题意 在一个圆环串中找一个最长的子序列,并且这个子序列是轴对称的. 思路 从对称轴上一点出发,向两个方向运动可以正好满足题意,并且可以证明如果抽选择的子环不是对称的话,其一定不是最长的. 倍长原序列, ...
- HDU 4745 最长回文子序列
题目大意 两只青蛙朝不同方向条,每次都到达值相同的位置,不能重复到达自己到过的地方,且不能飞跃已到过的地方 我们可以理解为这两只青蛙分别把整个序列遍历了一遍,依次走过所有的点,找到最多相同的点的个数, ...
- [LeetCode] 730. Count Different Palindromic Subsequences 计数不同的回文子序列的个数
Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...
- 动态规划求一个序列的最长回文子序列(Longest Palindromic Substring )
1.问题描述 给定一个字符串(序列),求该序列的最长的回文子序列. 2.分析 需要理解的几个概念: ---回文 ---子序列 ---子串 http://www.cnblogs.com/LCCRNblo ...
- NOIP2016提高组初赛(2)四、读程序写结果3、求最长回文子序列
#include <iostream> using namespace std; int lps(string seq, int i, int j) { int len1, len2; i ...
- 最长回文子序列(LPS)
问题描述: 回文是正序与逆序相同的非空字符串,例如"civic"."racecar"都是回文串.任意单个字符的回文是其本身. 求最长回文子序列要求在给定的字符串 ...
随机推荐
- 【转】web.xml中load-on-startup的作用
http://www.blogjava.net/xzclog/archive/2011/09/29/359789.html 如下一段配置,熟悉DWR的再熟悉不过了:<servlet> ...
- 流量分析系统---redis
1\启动redis 方法一: 修改了某些配置,具体步骤惨开下面的内容 [root@mini1 ~]# service redis stop/start 方法二: [root@mini1 bin]#cd ...
- 运行docker image 忘记添加端口号
docer inspect 容器id,查找IpAddress ,通过这个访问
- docker devise相关错误
rake aborted!Devise.secret_key was not set. Please add the following to your Devise initializer: con ...
- iOS UIWindow 与 windowLevel 学习
Pop几个关键点 KeyWindow :”The key window is the one that is designated to receive keyboard and other non- ...
- arcgis for flex map遮罩
效果1:map的遮罩(对整个map进行遮罩) 效果2:对某个图层进行遮罩
- hadoop02---高可用网站架构
tomcat每个请求都会占用内存cpu,tomcat没有代理功能.nginx是俄国人写的,nginx是静态资源服务器,既可以自己返回请求,也可以做代理进行转发,和负载均衡.Tomcat是动态资源jav ...
- QtGstreamer 编译
一 安装依赖项 1 安装cmake hdhuang@hdh-UBT:~/gstreamer/qt-gstreamer-0.10.2/build$ sudo apt-get install cmake ...
- Docker容器技术-优化Docker镜像
一.优化Docker镜像 1.降低部署时间 一个大的Docker应用是如何影响在新Docker宿主机上的部署时间. (1)编写Dockerfile创建一个大Docker镜像 [root@bogon ~ ...
- [NOI2008]奥运物流
题目 洛谷 BZOJ 做法 单环有向图毒瘤题 不考虑环和改变后继:\(\sum\limits{i=1}^n C_i\cdot K^{dep(i)}\) 考虑环无穷等比求极m:\(R(1)=\sum\l ...