Palindrome subsequence

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

Total Submission(s): 2836 Accepted Submission(s): 1160

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

//
// main.cpp
// 区间dp 1001
//
// Created by 陈永康 on 16/2/28.
// Copyright © 2016年 陈永康. All rights reserved.
//
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm> using namespace std;
char a[1005];
int dp[1005][1005];
int main()
{
int t;
scanf("%d",&t);
int cas=0;
while(t--)
{
scanf("%s",a+1);
int len=strlen(a+1);
memset(dp,0,sizeof(dp));
for(int i=1;i<=len;i++)
dp[i][i]=1;
for(int l=1;l<len;l++)
{
for(int i=1;i+l<=len;i++)
{
int j=i+l; dp[i][j]=(dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+10007)%10007;
if(a[i]==a[j])
dp[i][j]=(dp[i][j]+dp[i+1][j-1]+1+10007)%10007;
//dp[i][j]%=10007;
}
}
printf("Case %d: %d\n",++cas,dp[1][len]);
}
return 0;
}

求一个字符串数组的回文子串的数量

dp[i][j]区间i到j的回文子串数量,dp[i][j]=dp[i+1][j]+dp[i][j-1]-d[i+1][j-1],dp[i+1][j-1]是重复的部分这是a[i]不等于a[j]的情况,若二者相等,在这个基础上还要加上dp[i+1][j-1]+1。

HDU 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. HDU4632:Palindrome subsequence(区间DP)

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

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

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

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

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

  6. hdu4632 Palindrome subsequence (区间dp)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4632 题意:求回文串子串的的个数. 思路:看转移方程就能理解了. dp[i][j] 表示区 ...

  7. Cheapest Palindrome(区间DP)

    个人心得:动态规划真的是够烦人的,这题好不容易写出了转移方程,结果超时,然后看题解,为什么这些题目都是这样一步一步的 递推,在我看来就是懵逼的状态,还有那个背包也是,硬是从最大的V一直到0,而这个就是 ...

  8. hdu 5396 Expression(区间dp)

    Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...

  9. You Are the One HDU - 4283 (区间DP)

    Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...

随机推荐

  1. PHP利用memcache缓存技术提高响应速度

    PHP下memcache模块是一个高效的守护进程,提供用于内存缓存的过程式程序和面向对象的方便的接口,特别是对于设计动态web程序时减少对数据库的访问.memcache也提供用于通信对话(sessio ...

  2. linux常用命令中篇

    1.打印当月的日期

  3. js中的var

    vars变量预解析 JavaScript中,你可以在函数的任何位置声明多个var语句,并且它们就好像是在函数顶部声明一样发挥作用,这种行为称为 hoisting(悬置/置顶解析/预解析).当你使用了一 ...

  4. 详细分析css float 属性以及position:absolute 的区别

    1.float 属性定义元素在哪个方向浮动.以往这个属性总应用于图像,使文本围绕在图像周围,不过在 CSS 中,任何元素都可以浮动.浮动元素会生成一个块级框,而不论它本身是何种元素.div一个典型的块 ...

  5. downtown uptown

    Downtown is a term primarily used in North America by English speakers to refer to a city's core (or ...

  6. GIS-011-Cesium 使用 IIS设置

    .terrain Content-Type='application/octet-stream'

  7. Nginx(一)-- 初体验

    1.概念 Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 服务器. Nginx提供基本http服务,可以作 ...

  8. Zookeeper(二)-- 客户端操作命令

    一.前提 开启zookeeper服务端,用客户端连接.输入help,查看可使用命令,如下图所示: 操作无非就是增删改查等. 二.增加 格式:create [-s] [-e] path data acl ...

  9. Python 数据类型:列表

    一.列表介绍 1. 列表可以存储一系列的值,使用中括号来定义,每个元素之间用逗号隔开,形如 ['a', 'b', 'c', 'd']2. 列表与元组的区别是:列表中的元素是可变的,元组中的元素是不可变 ...

  10. C语言100个经典的算法之兔子总数计算内含printf的用法

    语言的学习基础,100个经典的算法 C语言的学习要从基础开始,这里是100个经典的算法-1C语言的学习要从基础开始,这里是100个经典的算法 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一 ...