题目链接: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,悲剧啊!

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <cstring>
  6. #include <queue>
  7. #include <vector>
  8.  
  9. #define maxn 1050
  10. #define INF 0x3f3f3f
  11. using namespace std;
  12. const int moder = ;
  13.  
  14. int dp[maxn][maxn];
  15. char s[maxn];
  16. int n;
  17.  
  18. int main()
  19. {
  20. //if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);}
  21. int T;
  22. cin>>T;
  23. for(int t=;t<=T;t++){
  24. scanf("%s",s);
  25. n = strlen(s);
  26. for(int i=;i<n;i++) dp[i][i] = ;
  27. for(int i=;i<n;i++) dp[i][i-] = ;
  28. for(int i=n-;i>=;i--)
  29. for(int j=i+;j<n;j++){
  30. dp[i][j] = dp[i][j-] + dp[i+][j] - dp[i+][j-];
  31. if(s[i] == s[j]) dp[i][j] += dp[i+][j-] + ;
  32. dp[i][j] = (dp[i][j] + moder) % moder; //没加moder,wa了好几次;
  33. }
  34. printf("Case %d: %d\n",t,dp[][n-]);
  35. }
  36. }

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. treeview右键添加新节点

    private void advTree1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Righ ...

  2. ios第三方工具

    1. DXPopover  带尖叫的提示框 2. MMDrawerController 最好的抽屉效果 3.MMProgressHUD  提示框 4.Reachability :网络链接检测 UIBu ...

  3. C#操作求出SQL中某一字段所有行的和方法!

    DataTable table = xx.sqlcha(sql1);//调数据库 ; foreach(DataRow row in table.Rows)//遍历所查出记录所有行 { v = v + ...

  4. webpack学习笔记一(入门)

    webpack集成了模块加载和打包等功能 ,这两年在前端领域越来越受欢迎.平时一般是用requirejs.seajs作为模块加载用,用grunt/gulp作为前端构建.webpack作为模块化加载兼容 ...

  5. Visual Studio vs2010 去掉中文注释红色下划线;去掉代码红色下划线;

    vs去掉下挂线也分两种: 1.去掉中文注释红色下划线,需要去掉VisualAssist下划线鸡肋功能: 1.选择Visual AssistX Options: 2.把如图所示的勾去掉,解决. 以后再次 ...

  6. Spring 整合Redis 出现 afterPropertiesSet signature: ()V) Incompatible argument to function 解决办法

    正在做SpringMVC+Redis整合的练习 使用的是 spring-data-redis 和 Jedis 配置好之后出现了以下错误: Caused by: java.lang.VerifyErro ...

  7. dede取得指定栏目的链接

    获取标签 typeid 为目录的 id {dede:type typeid='1'}       <a href="[field:typelink /]">[field ...

  8. SQL Server 连接字符串和身份验证

    SQL Server .NET Data Provider 连接字符串包含一个由一些属性名/值对组成的集合.每一个属性/值对都由分号隔开.         PropertyName1=Value1;P ...

  9. Python 基础-python函数

    函数    1.def    2.命名    3.函数体    4.return 返回值 def get_return(): a = 1 return a 函数参数有 形参和实参    定义几个形参就 ...

  10. 《C和指针》章节后编程练习解答参考——6.2

    <C和指针>——6.2 题目: 编写一个函数,删除源字符串中含有的子字符串部分. 函数原型: int del_substr(char *str, char const *substr); ...