HDU 4632 Palindrome subsequence(区间dp)
来源:互联网 发布:淘宝快递打单怎么装 编辑:程序博客网 时间:2024/06/05 08:01
Palindrome subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/Others)Total Submission(s): 3220 Accepted Submission(s): 1345
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.
(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
4aaaaaagoodafternooneveryonewelcometoooxxourproblems
Sample Output
Case 1: 1Case 2: 31Case 3: 421Case 4: 960
题意:计算回文子串的数量
n^2:
#include<iostream>#include<cstdio>#include<vector>#include<string.h>using namespace std;typedef vector<int> vec;typedef vector<vec> mat;typedef long long ll;const int MOD=1e4+7;char s[1001];int dp[1001][1001];int t,n,m,len,Casei;int main(){ // freopen("1.txt","r",stdin); Casei=1; for(~scanf("%d",&t);t--;) { scanf("%s",s); len=strlen(s); for(int i=0;i<1001;i++) dp[i][i]=1; for(int i=1;i<len;i++) for(int j=i-1;j>=0;j--) { dp[j][i]=(dp[j+1][i]+dp[j][i-1]-dp[j+1][i-1]+MOD)%MOD; if(s[i]==s[j]) dp[j][i]+=dp[j+1][i-1]+1; } printf("Case %d: %d\n",Casei++,dp[0][len-1]%MOD); } return 0;}
阅读全文
0 0
- HDU 4632 Palindrome subsequence(区间dp)
- HDU 4632 - Palindrome subsequence(区间DP)
- HDU 4632 Palindrome subsequence (区间DP)
- HDU 4632 Palindrome subsequence(区间dp)
- HDU 4632 Palindrome subsequence(区间DP)
- HDU 4632 Palindrome subsequence (区间DP)
- HDU 4632 Palindrome subsequence (区间DP)
- HDU 4632 Palindrome subsequence(区间dp)
- HDU 4632 Palindrome subsequence(区间DP)
- HDU 4632 Palindrome subsequence (区间dp 容斥定理)
- Hdu oj 4632 Palindrome subsequence(区间dp)
- hdu 4632 Palindrome subsequence (区间DP+容斥)
- HDU Palindrome subsequence(区间DP)
- Palindrome subsequence(区间dp)
- hdu 4632 Palindrome subsequence (dp)
- Hdu-4632 Palindrome subsequence DP
- HDU4632:Palindrome subsequence(区间DP)
- hdu4632 Palindrome subsequence--区间dp
- 工具类总结
- 基于IBM Bluemix部署Java Web项目实战演练
- 三分钟理解Java中字符串(String)的存储和赋值原理
- Android 相关工具插件版本经验总结
- (Mac/Windows)在终端中用finder/explorer打开文件夹的技巧
- HDU 4632 Palindrome subsequence(区间dp)
- LZW编码的学习与实现
- Eclipse环境安装C/C++插件CDT和Eclipse安装的插件卸载
- 网络协议之Tcp、Http
- Tensorflow Deep MNIST: Resource exhausted: OOM when allocating tensor with shape[10000,32,28,28]
- Tomcat热启动
- Spring Boot 的性能优化
- 打jar包,及运行jar包
- cocos利用菜单回调函数创建一个场景