link:http://acm.hdu.edu.cn/showproblem.php?pid=4632

refer to:

o(╯□╰)o……明明百度找的题解,然后后来就找不到我看的那份了,这位哥们对不住了……

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
char a[];
int dp[][];
const int MOD = ;
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
ios::sync_with_stdio(false);
int t; cin>>t;
for (int k = ; k <= t; ++k)
{
cin>>a; int len = strlen(a);
memset(dp, , sizeof(dp));
for (int i = ; i < len; ++i) for (int j = ; j < len; ++j)
if (i==j) dp[i][j] = ;
for (int i = ; i < len; ++i)
{
for (int j = ; i+j < len; ++j)
{
if (a[i+j] == a[j])
{
dp[j][i+j] = dp[j][i+j-] + dp[j+][i+j] + ;
}
else
{
dp[j][i+j] = dp[j+][i+j] + dp[j][i+j-] - dp[j+][i+j-];
}
dp[j][i+j] = (dp[j][i+j] + MOD)%MOD;
}
}
cout<< "Case "<<k<< ": "<<dp[][len-]<<endl;
}
return ;
}
/*
模拟一下第二个样例 aaaaa 就懂了
*/

o(╯□╰)o
永远感觉规划是一个很神奇的东西,比如这道。想明白了就感觉很神奇~

hdu4632 Palindrome subsequence ——区间动态规划的更多相关文章

  1. hdu4632 Palindrome subsequence (区间dp)

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

  2. hdu4632 Palindrome subsequence 回文子序列个数 区间dp

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

  3. Hdu4632 Palindrome subsequence 2017-01-16 11:14 51人阅读 评论(0) 收藏

    Palindrome subsequence Problem Description In mathematics, a subsequence is a sequence that can be d ...

  4. HDU4632 Palindrome subsequence

    标签(空格分隔): 区间qp Palindrome subsequence \[求一个string的 回文子序列 的个数 \] 少废话,上代码. #include<bits/stdc++.h&g ...

  5. HDU4632:Palindrome subsequence(区间DP)

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

  6. 【HDU4632 Palindrome subsequence】区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意:给你一个序列,问你该序列中有多少个回文串子序列,可以不连续. 思路:dp[i][j]表示序 ...

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

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

  8. HDU 4632 Palindrome subsequence (区间DP)

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

  9. hdu-4632 Palindrome subsequence (回文子序列计数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 问题要求回答一串字符串中回文子序列的数量,例如acbca就有 a,c,b,c,a,cc,aa,a ...

随机推荐

  1. web api同源策略

    1.重写JsonMediaTypeFormatter public class JsonpMediaTypeFormatter : JsonMediaTypeFormatter { private s ...

  2. IDEA调试javaScript

            谈起JavaScript调试,大家可能想到的就是FireFox下的FireBug,这毫无疑问,FireBug基本已经成为JavaScript开发人员的必备工具.在本文中,将向大家介绍如 ...

  3. Servlet初识

    1.servlet的生命周期 servlet生命周期中的三大重要时刻 servlet从不存在状态迁移到初始化状态(能够为客户提供服务),首先是从构造函数开始,但是构造函数只是使其成为一个对象,而不是一 ...

  4. Rhel7的基本使用

    1.修改主机名 [root@localhost ~]# cat /etc/hostname localhost.localdomain[root@localhost ~]# hostnamectl s ...

  5. Memcache 详解

    这里收集了经常被问到的关于memcached的问题 一般的问题 什么是memcached? 从哪获得memcached? 怎么安装memcached? 哪些平台可以运行memcached? 什么情况下 ...

  6. ACM - KMP题目小结 (更新中)

    KMP算法题型大致有两类,一类是next数组的应用,一类是匹配问题. next数组大多数是求字符串周期,或者是与前缀后缀有关,也可以应用在DP中.需要对next数组有一定理解才能做得出. next数组 ...

  7. Mysql5.0以上 手工注入

    Mysql5.0以上 order by 23 http://www..com/productdet.php?&id=89 and 1=2 UNION SELECT 1,2,3,4,5,6,7, ...

  8. http请求利器: 今天配置出了RESTClient,用MAVEN构建了UI运行包

  9. python3爬虫初探(二)之requests

    关于请求网页,不得不提requests这个库,这是爬虫经常用到的一个第三方库,用pip安装即可. requests用法很多,这里只写一些基础的,其他高级功能可参考官方文档. import reques ...

  10. MySQL创建数据表

    *  创建数据表 * *       *      一.什么是数据表 * *           * *      二.创建数据表的SQL语句模型 * *          DDL * *       ...