博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu4632
阅读量:6891 次
发布时间:2019-06-27

本文共 1986 字,大约阅读时间需要 6 分钟。

Palindrome subsequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/Others) Total Submission(s): 1538    Accepted Submission(s): 635

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 = <S
x1, S
x2, ..., S
xk> and
Y = <S
y1, S
y2, ..., S
yk> , if there exist an integer i (1<=i<=k) such that xi != yi, the subsequence X and Y should be consider different even if S
xi
 = S
yi. 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

一个DP,比赛时DP的状态搞错了.....

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 using namespace std; 9 #define ll long long int10 char a[1005];11 ll b[1005][1005];12 int main()13 {14 int n,i,m,j,t;15 cin>>n;16 for(i=0;i
=0;t--)25 {26 if(a[t]!=a[j])27 b[t][j]=(b[t+1][j]+b[t][j-1]-b[t+1][j-1]+10007)%10007;28 else 29 b[t][j]=(b[t+1][j]+b[t][j-1]+1)%10007;30 }31 printf("Case %d: %d\n",i+1,b[0][m-1]);32 }33 }
View Code

 

 

转载于:https://www.cnblogs.com/ERKE/p/3256954.html

你可能感兴趣的文章
iOS单例模式
查看>>
setTimeout()与setInterval()的区别
查看>>
python模块详解 XML
查看>>
微信公众平台开发文档 获取关注者列表
查看>>
[若有所悟]我看日式外包项目软件过程
查看>>
java 学习笔记-数组(三)
查看>>
jQuery打印Html页面自动分页
查看>>
获取css规则
查看>>
vue的基础使用
查看>>
UIAlertView添加textField
查看>>
Keystone中间件WSGI环境变量总结
查看>>
通过phoenix在hbase上创建二级索引,Secondary Indexing
查看>>
SpringMVC静态资源拦截的问题
查看>>
maven jetty运行时,js无法保存
查看>>
动态规划------平均切分数组之和为两部分
查看>>
python中的I/O
查看>>
面向对象数据访问添加数据和删除数据
查看>>
关于链表的基本操作
查看>>
移动端UI设计的经验总结
查看>>
中间件
查看>>