hdu4632 Palindrome subsequence ——区间动态规划
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 ——区间动态规划的更多相关文章
- hdu4632 Palindrome subsequence (区间dp)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4632 题意:求回文串子串的的个数. 思路:看转移方程就能理解了. dp[i][j] 表示区 ...
- hdu4632 Palindrome subsequence 回文子序列个数 区间dp
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- 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 ...
- HDU4632 Palindrome subsequence
标签(空格分隔): 区间qp Palindrome subsequence \[求一个string的 回文子序列 的个数 \] 少废话,上代码. #include<bits/stdc++.h&g ...
- HDU4632:Palindrome subsequence(区间DP)
Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...
- 【HDU4632 Palindrome subsequence】区间dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意:给你一个序列,问你该序列中有多少个回文串子序列,可以不连续. 思路:dp[i][j]表示序 ...
- HDU 4632 Palindrome subsequence(区间dp,回文串,字符处理)
题目 参考自博客:http://blog.csdn.net/u011498819/article/details/38356675 题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. ...
- HDU 4632 Palindrome subsequence (区间DP)
题意 给定一个字符串,问有多少个回文子串(两个子串可以一样). 思路 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字符串中[i,j]位置中出现的回文子序 ...
- hdu-4632 Palindrome subsequence (回文子序列计数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 问题要求回答一串字符串中回文子序列的数量,例如acbca就有 a,c,b,c,a,cc,aa,a ...
随机推荐
- WDCP管理面板安装启动EXIF、bcmath完整步骤
一般我们网站建设的需要,如果使用WDCP面板默认的功能就足够使用,如果需要特殊程序的特定组件支持,就需要独立的安装支持组件.比如一位朋友的程序需要支持EXIF.bcmath组件,这不老蒋寻找解决方法, ...
- async = require('async')
var mongoose = require('mongoose'), async = require('async'); mongoose.connect('localhost', 'learn-m ...
- C++质因式分解
分解质因数是将一个数差分成为几个质数相乘,本函数n初始取2 void prim(int m, int n) { if (m > n) { while (m%n) n++; m/=n; prim( ...
- [windows操作系统]windows模块
smss.exe csrss.exe Client/Server Runtime Server Subsystem
- 记录一些容易忘记的属性 -- UIButton
//设置按钮文字字体(这个只在自定义button时有效) btn1.titleLabel.font = [UIFont systemFontOfSize:30]; showsTouchWhenH ...
- 如何搭建MVC + EF 框架
1.搭建MVC框架 1.1 VS2010:需要安装WPI 安装 ASP.NET MVC 4 和Visual Studio 2010 系统必备组件 如果上述链接无法打开,请访问:http://www.a ...
- MySQL的简单查询
1.普通查询 select * from info; #查询所有内容 select Code,Name from Info #查询某几列 2.条件查询 select * from Info where ...
- electronic data interchange 电子数据交换
electronic data interchange 电子数据交换
- 在VS2010 中兼容Qt4和Qt5
1,同时安装Qt4和Qt5 Qt_add,然后在 2. 如果之前的项目使用Qt4编写的,如果新添加新的类和ui的话,一定要选择Qt Add_in 1.1.11,不然就无法生成moc文件,随便选择 Ch ...
- MVC学习IIS的不同版本(一)
一:IIS5.0运行在进程InetInfo.exe中,该进程寄宿着一个名为World Wide Publishing Service(W3VC)的window服务. W3VC的主要功能:包括HTTP请 ...