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. node开发 npm install -g express-generator@4

    Node forever : 1,forever start --uid test start app.js 2,forever start --uid test start -a app.js 3, ...

  2. 浏览器Firefox新标签页默认打开地址设置

    1.地址栏输入about:config 2.找到browser.newtab.url 修改它的值为你想要的地址,如:https://www.baidu.com

  3. 中国广核集团:BPM与ERP紧密结合

    全球能源消耗不断增长,电能已经达到了无可替代的位置.同时,传统的电力供应模式正在受新模式的影响,营造更具价值的生态系统.面对挑战,核电企业在提高能效并降低成本的同时,也迫切需要进行转型.面对公众对可再 ...

  4. .net异常小总

    1.  ExecuteReader:CommandText属性尚未初始化 即:没有对sqlCommand对象的CommandText属性赋值,即没有写sql语句. 2.  由于代码已经过优化或者本机框 ...

  5. iOS 使用两个tableview的瀑布流

    代码 悦德财富:https://www.yuedecaifu.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...

  6. c# access插入null值

    c# 插入access数据库 提示错误: Parameter @DeviceLocation has no default value. 参数@DeviceLocation 的有没有默认值. Stri ...

  7. protected 和default的区别

    default:包内可见,包外不可见 protected:包内可见,包外不可见,但是包外继承之后可见.

  8. linux下的deb/rpm文件的说明和安装方法

    1.    deb 是 ubuntu .debian 的格式.    rpm 是 redhat .fedora .suse 的格式. 他们不通用(虽然可以转换一下). deb是debian发行版的软件 ...

  9. C#注册表常用操作

    1:加键 改值 Microsoft.Win32.RegistryKey Key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( @" ...

  10. PHP面向对象的继承

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...