Palindrome subsequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/Others)

Total Submission(s): 2595    Accepted Submission(s): 1039

Problem Description
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence <A, B, D> is a subsequence of <A, B, C,
D, E, F>.

(http://en.wikipedia.org/wiki/Subsequence)



Given a string S, your task is to find out how many different subsequence of S is palindrome. Note that for any two subsequence X = <Sx1, Sx2, ..., Sxk> and Y = <Sy1, Sy2, ..., Syk> , if there
exist an integer i (1<=i<=k) such that xi != yi, the subsequence X and Y should be consider different even if Sxi = Syi. Also two subsequences with different length should be considered different.
 
Input
The first line contains only one integer T (T<=50), which is the number of test cases. Each test case contains a string S, the length of S is not greater than 1000 and only contains lowercase letters.
 
Output
For each test case, output the case number first, then output the number of different subsequence of the given string, the answer should be module 10007.
 
Sample Input
4
a
aaaaa
goodafternooneveryone
welcometoooxxourproblems
 
Sample Output
Case 1: 1
Case 2: 31
Case 3: 421
Case 4: 960
 
Source
 

/*
题意:问一个字符串的会问序列有多少个
dp[i][j]=(dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]);
if(c[i]==c[j]) 那么加上中间的dp[i+1][j-1],由于能够和i,j形成新的
还要加上 1 (i 和 j 形成字符串) */ #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map> #define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1) #define bug printf("hihi\n") #define eps 1e-8
typedef __int64 ll; using namespace std; #define mod 10007
#define INF 0x3f3f3f3f
#define N 1005 int dp[N][N];
int len;
char c[N]; int main()
{
int i,j,t,ca=0;
scanf("%d",&t);
while(t--)
{
scanf("%s",c);
len=strlen(c);
memset(dp,0,sizeof(dp));
for(i=0;i<len;i++)
dp[i][i]=1; for(i=len-1;i>=0;i--)
for(j=i+1;j<len;j++)
{
dp[i][j]=(dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+mod)%mod;
if(c[i]==c[j])
dp[i][j]=(dp[i][j]+dp[i+1][j-1]+1+mod)%mod;
}
printf("Case %d: %d\n",++ca,(dp[0][len-1]+mod)%mod);
}
return 0;
}

HDU 4632 Palindrome subsequence(区间dp)的更多相关文章

  1. HDU 4632 Palindrome subsequence(区间dp,回文串,字符处理)

    题目 参考自博客:http://blog.csdn.net/u011498819/article/details/38356675 题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. ...

  2. HDU 4632 Palindrome subsequence (区间DP)

    题意 给定一个字符串,问有多少个回文子串(两个子串可以一样). 思路 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字符串中[i,j]位置中出现的回文子序 ...

  3. HDU 4632 Palindrome subsequence(区间DP求回文子序列数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题目大意:给你若干个字符串,回答每个字符串有多少个回文子序列(可以不连续的子串).解题思路: 设 ...

  4. HDU 4632 Palindrome subsequence (区间DP)

    Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/ ...

  5. HDU 4632 Palindrome subsequence & FJUT3681 回文子序列种类数(回文子序列个数/回文子序列种数 容斥 + 区间DP)题解

    题意1:问你一个串有几个不连续子序列(相同字母不同位置视为两个) 题意2:问你一个串有几种不连续子序列(相同字母不同位置视为一个,空串视为一个子序列) 思路1:由容斥可知当两个边界字母相同时 dp[i ...

  6. HDU 4632 Palindrome subsequence (2013多校4 1001 DP)

    Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/ ...

  7. HDU4632:Palindrome subsequence(区间DP)

    Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...

  8. HDU 4632 CF 245H 区间DP(回文)

    先说HDU 4632这道题,因为比较简单,题意就是给你一个字符串,然后给你一个区间,叫你输出区间内所有的回文子序列,注意是回文子序列,不是回文字串. 用dp[i][j]表示区间[i,j]内的回文子序列 ...

  9. [HDU4362] Palindrome subsequence (区间DP)

    题目链接 题目大意 给你几个字符串 (1<len(s)<1000) ,要你求每个字符串的回文序列个数.对于10008取模. Solution 区间DP. 比较典型的例题. 状态定义: 令 ...

随机推荐

  1. Eclipse默认标签TODO,XXX,FIXME和自定义标签

    1 TODO 表示需要实现,但目前还未实现的功能 2 XXX 勉强可以工作,但是需要改进的功能 3 FIXME 代码是错误的,不能工作,需要修复 4.自定义标签 window-->prefere ...

  2. 微信支付报错:统一下单和拉起支付的appid不一致(原创)

    微信支付报错:统一下单和拉起支付的appid不一致 错误码:-2 提示参考: 参考统一下单的API (谦信君原创,转载请注明来源) 原因排查: 我们做的是APP微信支付 客户端向我服务端发请求,获取预 ...

  3. 解决 WP迁移后出现的404错误

    项目迁移 WordPress 后仅首页正常,其它页面全部 404.时隔一年,再度遇到这问题,总结和梳理一下. 1.想办法登录后台,刷新一次“设置”中的“固定链接”.比如换成默认后保存,再设回原先设置并 ...

  4. deepin使用root身份运行

    https://blog.csdn.net/guanripeng/article/details/79630619

  5. Dart类

    Dart中没有访问控制符,无论类还是方法默认都是public 1.构造函数 构造函数可以没有方法体,并且this可以直接在传参时直接对实例赋值 Bicycle(this.cadence, this.s ...

  6. 洛谷——P1604 B进制星球

    P1604 B进制星球 题目背景 进制题目,而且还是个计算器~~ 题目描述 话说有一天,小Z乘坐宇宙飞船,飞到一个美丽的星球.因为历史的原因,科技在这个美丽的星球上并不很发达,星球上人们普遍采用B(2 ...

  7. 10、Django实战第10天:找回密码

    今天完成的功能是:用户忘记密码后,通过注册邮箱重置密码... 首先还是把前端页面准备好,把forgetpwd.html复制到templates目录下 编辑users.views.py,创建一个忘记密码 ...

  8. sqlplus terminators - Semicolumn (;), slash (/) and a blank line

    The problem here is the way SQL*Plus interprets the commands passed to it. Remember the "SQL co ...

  9. 【分块】bzoj3226 [Sdoi2008]校门外的区间

    题解见 : http://blog.csdn.net/iamzky/article/details/41088151 ORZ ZKY 2个懒标记:是否翻转,覆盖成了什么. 怎么处理一个块上有两个标记的 ...

  10. python3-开发面试题(python)6.22基础篇(1)

    1.为什么学习Python? 1.语言排行榜 2.语言本身简洁,优美,功能超级强大的 3.跨平台 4.非常火爆的社区 5.用的公司的多 2.通过什么途径学习的Python? 某宝2.8就搞定了,跟着视 ...