区间dp

  1. /* ***********************************************
  2. Author :guanjun
  3. Created Time :2016/6/30 23:24:27
  4. File Name :1025.cpp
  5. ************************************************ */
  6. #include <iostream>
  7. #include <cstring>
  8. #include <cstdlib>
  9. #include <stdio.h>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <queue>
  13. #include <set>
  14. #include <map>
  15. #include <string>
  16. #include <math.h>
  17. #include <stdlib.h>
  18. #include <iomanip>
  19. #include <list>
  20. #include <deque>
  21. #include <stack>
  22. #define ull unsigned long long
  23. #define ll long long
  24. #define mod 90001
  25. #define INF 0x3f3f3f3f
  26. #define maxn 10010
  27. #define cle(a) memset(a,0,sizeof(a))
  28. const ull inf = 1LL << ;
  29. const double eps=1e-;
  30. using namespace std;
  31. priority_queue<int,vector<int>,greater<int> >pq;
  32. struct Node{
  33. int x,y;
  34. };
  35. struct cmp{
  36. bool operator()(Node a,Node b){
  37. if(a.x==b.x) return a.y> b.y;
  38. return a.x>b.x;
  39. }
  40. };
  41.  
  42. bool cmp(int a,int b){
  43. return a>b;
  44. }
  45. ll dp[][];
  46. char s[];
  47. int main()
  48. {
  49. #ifndef ONLINE_JUDGE
  50. freopen("in.txt","r",stdin);
  51. #endif
  52. //freopen("out.txt","w",stdout);
  53. int T;
  54. cin>>T;
  55. for(int t=;t<=T;t++){
  56. scanf("%s",s+);
  57. int n=strlen(s+);
  58. cle(dp);
  59. for(int len=;len<=n;len++){
  60. for(int i=;i+len-<=n;i++){
  61. int j=i+len-;
  62. dp[i][j]+=dp[i+][j]+dp[i][j-]-dp[i+][j-];
  63. if(s[i]==s[j])dp[i][j]+=dp[i+][j-]+;
  64. }
  65. }
  66. printf("Case %d: %lld\n",t,dp[][n]);
  67. }
  68. return ;
  69. }

Lightoj 1025 - The Specials Menu的更多相关文章

  1. Lightoj 1025 - The Specials Menu (区间DP)

    题目链接: Lightoj 1025 - The Specials Menu 题目描述: 给出一个字符串,可以任意删除位置的字符,也可以删除任意多个.问能组成多少个回文串? 解题思路: 自从开始学dp ...

  2. 1025 - The Specials Menu

    1025 - The Specials Menu    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  3. Light OJ 1025 - The Specials Menu(动态规划-区间dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1025 题目大意:一串字符, 通过删除其中一些字符, 能够使这串字符变成回文串. ...

  4. Light OJ 1025 - The Specials Menu(区间DP)

    题目大意:     给你一个字符串,问有多少种方法删除字符,使得剩下的字符是回文串. 有几个规定: 1.空串不是回文串 2.剩下的字符位置不同也被视为不同的回文串.如:AA有三种回文串 A, A, A ...

  5. The Specials Menu LightOJ - 1025

    The Specials Menu LightOJ - 1025 题意:在给定的字符串中删去一些字符,使其成为回文串(不能全部都删).求方案数. 方法:常规的区间dp.ans[i][j]表示在i到j的 ...

  6. 【lightoj-1025】The Specials Menu(区间DP)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1025 [题目大意] 求一个字符串删去任意字符可以构成多少个不同的回文串 [分析 ...

  7. LightOJ1025 The Specials Menu(区间DP)

    给一个字符串,问有几种删字符的方式使删后的非空字符串是个回文串. 当然区间DP:dp[i][j]表示子串stri...strj的方案数 感觉不好转移,可能重复算了.我手算了"AAA" ...

  8. lightoj 1025 区间dp

    #include<bits/stdc++.h> using namespace std; typedef long long ll; char a[70]; ll dp[70][70]; ...

  9. lightoj 1025【区间DP】

    题意: 给出一个word,求有多少种方法你从这个word清除一些字符而达到一个回文串. 思路: 区间问题,还是区间DP: 我判断小的区间有多少,然后往外扩大一点. dp[i,j]就代表从i到j的方案数 ...

随机推荐

  1. [第一波模拟\day3\T3]{益智游戏}(game.cpp)

    [问题描述] 小P和小R在玩一款益智游戏.游戏在一个正权有向图上进行. 小P控制的角色要从A点走最短路到B点,小R控制的角色要从C点走最短路到D点. 一个玩家每回合可以有两种选择,移动到一个相邻节点或 ...

  2. mybatis自动映射和手动映射

    一对一查询 第一种方法: <!-- 查询所有订单信息 --> <select id="findOrdersList" resultType="cn.it ...

  3. hihoCoder#1105 题外话·堆

    原题地址 有没有更优雅地堆模板啊,总感觉我写的有些啰嗦 代码: #include <iostream> using namespace std; #define MAX_NODE 1000 ...

  4. [POJ1984]Navigation Nightmare

    [POJ1984]Navigation Nightmare 试题描述 Farmer John's pastoral neighborhood has N farms (2 <= N <= ...

  5. codeforces #299 div 2

    (总算是5题都做完了- -) 暂时做了4题,先放一下有时间做最后一题(当然如果我真的能做出的话...)(看了大神的代码总算是理解了E题,做完发现也没那么难,果然想出一个思路的过程对于我这种弱渣来说还是 ...

  6. 【概率dp】C. Race to 1 Again

    https://www.bnuoj.com/v3/contest_show.php?cid=9146#problem/C [题意] 给定一个数D,每次随机选取这个数的一个因子x得到新的数D=D/x,知 ...

  7. BZOJ1739: [Usaco2005 mar]Space Elevator 太空电梯

    n<=400个东西,每个东西有高度<=100,这种东西在堆放过程中不得超过的最大高度<=40000,以及每个东西的个数<=10,求最高能堆多高. 算了下背包复杂度不太对然后开了 ...

  8. msp430项目编程07

    msp430中项目---简单计算器 1.扫描键盘工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习

  9. HDU 5695 Gym Class

    拓扑排序. #include<cstdio> #include <iostream> #include<cstring> #include<cmath> ...

  10. hdu6110(线段树+lca)

    题目 http://acm.hdu.edu.cn/showproblem.php?pid=6110 分析 注意到,若干条路径的交一定也是条路径 我们可以维护一个线段树,seg[l..r]存着第l条~第 ...