题目链接: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. javascript-图片横向无缝隙滚动

    <style type="text/css"> <!-- ul,li,div{margin:0; padding:0; font-size:12px;} #dem ...

  2. ASIHttpRequest网络请求第三方类库使用方法详解

    一. 第一步首先你要从网络上下载ASIHttpRequestlib, 下载以后解压,增加到你的工程里面, 这个时间检查工程内部是否已经导入成功,文件结构如下: ASIHTTPRequestConfig ...

  3. Moving a Subversion Repository to Another Server

    Moving a subversion repository from one server to another, while still preserving all your version h ...

  4. java 对于url地址的实体符号的处理

    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 <dependency> <g ...

  5. 在CentOS 7中轻松安装Atomic应用(atomicapp)

    sudo yum install docker atomic etcd kubernetes sudo systemctl enable docker.service sudo systemctl s ...

  6. shell用if

    --------- shell用if出错了,Why? shell if 实例: site=github.com/fankcoder if [ $site == github.com/fankcoder ...

  7. C#中foreach遍历学习笔记

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...

  8. [r]How To Use Git To Create A Key

    怎样生成公钥(via) 工作流程 安装设置 git 下载最新版本的git http://git-scm.com/downloads 当你安装完成git的时候,你需要简单的配置一下,打开终端: 用户名 ...

  9. 开发DZ插件教程

    插件制作的基本思路是:(初学者适用)1.形成插件思路2.制作插件界面3.构架程序模块4.搭建存储数据5.填充功能语句6.检查应用错误7.完善插件功能 前言:为方便互联网数万Discuz!爱好者,更加深 ...

  10. java 知识结构

    JAVA基础阶段 阶段 技术名称 技术内容 T线 JavaSE JAVA 开发基础知识 | Eclipse 开发环境 | JavaSE 7.0 API | JavaSE 8.0新特性 | 多线程技术 ...