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 ...
随机推荐
- 从ajax获取的数据无法通过Jquery选择器来调用事件
如果标签是动态生成的,比如说div.tr.td等,若需通过Jquery来获取事件,那么需要用live来绑定相应的事件. 比如说绑定div的click事件 $("div").live ...
- Rhel6-haproxy+keepalived配置文档
系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.119:haproxy,keepalived server19.exa ...
- linux之开发板与宿主机通信--ftp使用
在目标板终端上输入命令: # ftp 192.16.77.66 //192.16.77.66是宿主机IP # cd /home/ //这里可以使用linux命令,但不能使有TAB键 # get ...
- windows命令行及批处理文件小结
1.命令Shell概述(Command shell overview): The command shell is a separate software program that provides ...
- ajax异步文件上传,iframe方式
不是我写的,我看了他的,思路很明确: 实现思路: 在js脚本中动态创建form,动态创建form中的内容,将文件上传的内容以隐藏域的方式提交过去,然后写好回调等. 感觉思路不难,但是我写不出来,感觉需 ...
- c# access插入null值
c# 插入access数据库 提示错误: Parameter @DeviceLocation has no default value. 参数@DeviceLocation 的有没有默认值. Stri ...
- iOS 中 #import同@class之间的区别
很多刚开始学习iOS开发的同学可能在看别人的代码的时候会发现有部分#import操作写在m文件中,而h文件仅仅使用@class进行声明,不禁纳闷起来,为什么不直接把#import放到h文件中呢? 这是 ...
- hd oj2025
Ps:尼玛这道题简直坑爹...就是直接比较ascii码....无脑题,想复杂了... 代码:#include "stdio.h"#include "string.h&qu ...
- openstack中运行定时任务的两种方法及源代码分析
启动一个进程,如要想要这个进程的某个方法定时得进行执行的话,在openstack有两种方式: 一种是通过继承 periodic_task.PeriodicTasks,另一种是使用loopingcall ...
- spring mvc + freemarker优雅的实现邮件定时发送
1. spring mvc工程中引入相关freemarker\mail的包 如:pom.xml中加入类似 <dependency> <groupId>javax.mail< ...