hdu 4632(区间dp)
Palindrome subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/Others)
Total Submission(s): 2858 Accepted Submission(s): 1168
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 <A, B, D> is a
subsequence of <A, B, C, D, E, F>.
(http://en.wikipedia.org/wiki/Subsequence)
Given
a string S, your task is to find out how many different subsequence of S
is palindrome. Note that for any two subsequence X = <Sx1, Sx2, ..., Sxk> and Y = <Sy1, Sy2, ..., Syk>
, if there exist an integer i (1<=i<=k) such that xi != yi, the
subsequence X and Y should be consider different even if Sxi = Syi. Also two subsequences with different length should be considered different.
first line contains only one integer T (T<=50), which is the number
of test cases. Each test case contains a string S, the length of S is
not greater than 1000 and only contains lowercase letters.
each test case, output the case number first, then output the number of
different subsequence of the given string, the answer should be module
10007.
a
aaaaa
goodafternooneveryone
welcometoooxxourproblems
Case 2: 31
Case 3: 421
Case 4: 960
题意:找出一个串中所有"回文串"的个数。这个回文串的意思是:所有子串(包裹不相邻的)只要满足回文串的性质都属于回文串.
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#define N 1005
using namespace std; int dp[][];
char str[];
int main()
{
int tcase;
int k = ;
scanf("%d",&tcase);
while(tcase--){
scanf("%s",str+);
int len = strlen(str+);
for(int i=;i<=len;i++) dp[i][i]=;
for(int l=;l<=len;l++){
for(int i=;i<=len-l+;i++){
int j=i+l-;
dp[i][j] = (dp[i+][j]+dp[i][j-]-dp[i+][j-]+)%;///子问题推出父问题(减掉重复子问题)
///有减号要加mod防止出现负数
if(str[i]==str[j]){
dp[i][j] = (dp[i][j]+dp[i+][j-]+)%;///如果str[i]str[j]相等,那么会多出dp[i+1][j-1]+1个回文串
}
}
}
printf("Case %d: %d\n",k++,dp[][len]);
}
return ;
}
hdu 4632(区间dp)的更多相关文章
- HDU 4632 区间DP 取模
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...
- hdu 4632区间dp 回文字串计数问题
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- hdu 4632区间 dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 用点容斥原理转移状态, dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+ ...
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化
HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...
- HDU 4293---Groups(区间DP)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...
- String painter HDU - 2476 -区间DP
HDU - 2476 思路:分解问题,先考虑从一个空串染色成 B串的最小花费 ,区间DP可以解决这个问题 具体的就是,当 str [ l ] = = str [ r ]时 dp [ L ] [ R ] ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 4570(区间dp)
E - Multi-bit Trie Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀
A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- distcc配置
原理图: OS: ubuntu Server 12.04 1.安装 apt-get install distcc 2.配置 将文件/etc/default/distcc修改为如下格式 STARTDIS ...
- python 面试题(1)
好用简洁的大数据技术:python.hadoop.R 慢慢学习,随时分享 1.什么是Python?使用Python有什么好处? Python是一种编程语言,它有对象.模块.线程.异常处理和自动内存管理 ...
- python实现堆栈、队列
一.利用python列表实现堆栈和队列 堆栈: 堆栈是一个后进先出的数据结构,其工作方式就像生活中常见到的直梯,先进去的人肯定是最后出. 我们可以设置一个类,用列表来存放栈中的元素的信息,利用列表的a ...
- Jumpserver代码规范
Jumpserver 项目规范(Draft) 语言框架 Python 3.6.1 (当前最新) Django 1.11 (当前最新) Flask 0.12 Luna (当前最新) Paramiko 2 ...
- 【Atcoder】ARC084 Small Multiple
[题意]求一个k的倍数使其数位和最小,输出数位和,k<=10^5. [算法]最短路 [题解]考虑极端情况数字是可能爆long long的(例如k*num=100...000),所以确定基本方向是 ...
- 【NOIP】提高组2013 积木大赛
[算法]找规律(听说还有写RMQ的www) [题解]ans+=(a[i]-a[i-1]) (i=1...n)(a[i]>a[i-1]) 后面比前面大k,说明要新叠加k个区间来达到所需高度.(看 ...
- gridveiw的使用
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- java爬虫框架jsoup
1.java爬虫框架的api jsoup:https://www.open-open.com/jsoup/
- div圆角
div{ -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px;}