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. Hibernate关系映射 一对一双向外键关联@OneToOne Annotation方式 双向关联和单向关联的区别

    首先还是来构造一个实际应用的场景,比如实体类车辆(Car),它具有以下属性:Id,品牌(brand),车牌(lisencePlate):实体类车牌(LisencePlate),它具有以下属性:Id,号 ...

  2. nest(inner) class

    嵌套类,摘自: http://www.ntu.edu.sg/home/ehchua/programmin/java/J4a_GUI.html A nested class has these prop ...

  3. 有一个TIME的类要求输出分和秒的值

    #include <iostream> /* run this program using the console pauser or add your own getch, system ...

  4. win7 自带计算机(for programmer)

    打开win7的Accessories, 看到Calculator, 点击打开计算器. 可以看到32位的2进制代码:

  5. PL/SQL如何调试Oracle存储过程

    from:http://jingyan.baidu.com/article/3a2f7c2e144d2826aed61167.html 调试过程对找到一个存过的bug或错误是非常重要的,Oracle作 ...

  6. vuex的简单使用

    使用vuex进行组件间数据的管理 npm i vuex -S main.js import Vue from 'vue' import App from './App.vue' import stor ...

  7. THINKPHP include 标签动态加载文件

    有时候需要在框架中动态的加载一些文件,文件名不确定,有控制器获取得到,想在模板中使用变量的形式进行加载,本以为这样写可以 结果不行 <include file="User/{$my_t ...

  8. Android NDK开发-1-环境搭建

    1.NDK介绍 Android NDK 是在SDK前面又加上了“原生”二字,即Native Development Kit,因此又被Google称为“NDK”.众所周知,Android程序运行在Dal ...

  9. /etc/logrotate.conf

    /etc/logrotate.conf 是 Logrotate 工具的一个配置文件,这个工具用来自动切割系统日志,Logrotate 是基于 cron 来运行的,如下: [root@localhost ...

  10. date类型数据插入

    --字段类型是dateinsert into tab(column) values(to_date('2017_06_30 11:38:22','yyyy-mm-dd hh24:mi:ss'));-- ...