题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632

用点容斥原理转移状态,

dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]

当 s[i] == s[j], 要加上 dp[i+1][j-1] + 1;

我就是想的太复杂,而这个题有卡时间,无限TLE,悲剧啊!

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector> #define maxn 1050
#define INF 0x3f3f3f
using namespace std;
const int moder = ; int dp[maxn][maxn];
char s[maxn];
int n; int main()
{
//if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);}
int T;
cin>>T;
for(int t=;t<=T;t++){
scanf("%s",s);
n = strlen(s);
for(int i=;i<n;i++) dp[i][i] = ;
for(int i=;i<n;i++) dp[i][i-] = ;
for(int i=n-;i>=;i--)
for(int j=i+;j<n;j++){
dp[i][j] = dp[i][j-] + dp[i+][j] - dp[i+][j-];
if(s[i] == s[j]) dp[i][j] += dp[i+][j-] + ;
dp[i][j] = (dp[i][j] + moder) % moder; //没加moder,wa了好几次;
}
printf("Case %d: %d\n",t,dp[][n-]);
}
}

hdu 4632区间 dp的更多相关文章

  1. HDU 4632 区间DP 取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...

  2. hdu 4632(区间dp)

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

  3. hdu 4632区间dp 回文字串计数问题

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

  4. hdu 4283 区间dp

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化

    HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...

  6. HDU 4293---Groups(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...

  7. String painter HDU - 2476 -区间DP

    HDU - 2476 思路:分解问题,先考虑从一个空串染色成 B串的最小花费 ,区间DP可以解决这个问题 具体的就是,当 str [ l ] = = str [ r ]时 dp [ L ] [ R ] ...

  8. 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) ...

  9. HDU 4570(区间dp)

    E - Multi-bit Trie Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. (转)asp.net分页存储过程

    Asp.Net分页存储过程 SQL分页语句 一.比较万能的分页: sql代码: 1 2 3 select top 每页显示的记录数 * from topic where id not in  (sel ...

  2. godaddy_关于产品退款

    You're chatting with Danny.Danny - Thank you for contacting live chat. My name is Danny. How can I a ...

  3. select、poll、epoll用法

    我们先从著名的C10K问题开始探讨,由于早期在网络还不普及的时候,互联网的用户并不是很多,一台服务器同时在线100个用户估计在当时已经算是大型应用了.但是随着互联网的发展,用户群体迅速的扩大,每一个用 ...

  4. 一句实现jquery导航栏

    /*mine 才疏学浅,望大神绕行 */ .current{ color: red; font-size: large; } $(function(){ //实现点击标题的css和.lev1下面的a标 ...

  5. Javascript参数传递中值和引用的一种理解

    值(value)和引用(reference)是各种编程语言老生常谈的话题,js也不例外. 我将剖析一个例子的实际运行过程,跟大家分享我对js参数传递中的值和引用的理解. 参考官网数据类型的两种分类,本 ...

  6. mysql中显示方式的切换

    1. mysql中如果使用\G,则':'不用写.如果\G后面跟':'则会报"error:no query specified"错误.请知晓. 2. mysql在登陆时,mysql ...

  7. [Python]更加Pythonic的多个List合并和Python的安利

    原题: https://segmentfault.com/q/1010000005904259 问题: 倘若存在 L=[ [1,2,3],[4,5,6],[7,8,9]] 这样的列表,如何把合并成[1 ...

  8. 简单工厂模式的C++实现

    用简单工厂模式实现一个计算器类: #include <iostream> #include <string> using namespace std; class Operat ...

  9. Solr4.8.0源码分析(25)之SolrCloud的Split流程

    Solr4.8.0源码分析(25)之SolrCloud的Split流程(一) 题记:昨天有位网友问我SolrCloud的split的机制是如何的,这个还真不知道,所以今天抽空去看了Split的原理,大 ...

  10. 单例模式在Unity中的应用

    起因:每个游戏场景中都会有许多的游戏对象,而各个游戏场景之间也是同等的关系.如何去管理它们,是我们要解决的问题. 场景中各脚本间的直接访问,会在各脚本间形成一个巨大而又混乱的网络,这给以后代码的维护带 ...