题目大意:

    给你一个字符串,问有多少种方法删除字符,使得剩下的字符是回文串。
有几个规定:
1.空串不是回文串
2.剩下的字符位置不同也被视为不同的回文串。如:AA有三种回文串 A, A, AA
================================================================================================
 
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int MAXN = ;
char str[MAXN];
LL dp[MAXN][MAXN];
LL DFS(int L,int R)
{
if(L > R) return ;
if(dp[L][R]) return dp[L][R];
if(L == R) return dp[L][R] = ; dp[L][R] = DFS(L+,R) + DFS(L,R-) - DFS(L+,R-);
if(str[L] == str[R])
dp[L][R] += DFS(L+, R-) + ;
return dp[L][R];
} int main()
{
int T, cas = ;
scanf("%d", &T);
while(T --)
{
memset(dp, , sizeof(dp));
scanf("%s", str);
int len = strlen(str);
printf("Case %d: %lld\n",cas ++, DFS(,len-));
} return ;
}

Light OJ 1025 - The Specials Menu(区间DP)的更多相关文章

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

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

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

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

  3. Light OJ 1031 - Easy Game(区间DP)

    题目大意: 给你一个n,代表n个数字,现在有两个选手,选手A,B轮流有有一次机会,每个选手一次可以得到一个或者多个数字,从左侧或者右侧,但是不能同时从两边取数字,当所有的数字被取完,那么游戏结束.然后 ...

  4. Light oj 1044 - Palindrome Partitioning(区间dp)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 dp[i][j]表示i到j直接的最小回文区间个数,直接看代码 #include ...

  5. 1025 - The Specials Menu

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

  6. Lightoj 1025 - The Specials Menu

    区间dp /* *********************************************** Author :guanjun Created Time :2016/6/30 23:2 ...

  7. light oj 1140 - How Many Zeroes? 数位DP

    思路:dp[i][j]:表示第i位数,j表示是否有0. 代码如下: #include<iostream> #include<stdio.h> #include<algor ...

  8. Light OJ 1021 - Painful Bases(状态压缩DP)

    题目大意: 给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的. 题目解析: #include<cstdio> #include<cstring ...

  9. Light OJ 1004 - Monkey Banana Problem(DP)

    题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...

随机推荐

  1. Android绘制流程

    一.前言 1.1.C++界面库 MFC.WTL.DuiLib.QT.Skia.OpenGL.Android里面的画图分为2D和3D两种: 2D是由Skia 来实现的,3D部分是由OpenGL实现的. ...

  2. Android自定义Notification并没有那么简单

    背景 最近需要实现一个自定义Notification的功能.网上找了找代码,解决方案就是通过RemoteViews来实现.但是在实现过程中遇到不少问题,网上也没有很好的文章描述这些问题,所以在这里做个 ...

  3. 转战WebApp: 最适合Android开发者的WebApp框架

    随着移动端设备越来越多, 微信应用号即将发布, 越来越多的页面需要被移动浏览器承载, HTML5开发大热, 我们需要掌握Web开发的技能来适应时代变化. 合适的WebApp框架 AndroidUI4W ...

  4. (转)if语句优化

    一.使用常见的三元操作符  if (foo) bar(); else baz(); ==> foo?bar():baz(); if (!foo) bar(); else baz(); ==> ...

  5. HTML5-36d嗨起^_^

    如果一个前端不会写css那必然会被贻笑大方,利用html5新增的一些c3属性可以做许许多多炫酷的效果. 大家先看我写的一个小demo: http://zpf92.github.io/build/ 这个 ...

  6. How to Make LastPass Even More Secure with Google Authenticator

    Google Authenticator LastPass supports Google Authenticator, which is officially available as an app ...

  7. Spot light工具集

    Spot light on UNIX 安装没什么问题 Spot light on Oracle  必须安装32位的客户端,不然搞死你 两者的界面都是吊炸天啊

  8. Linux下使用NMON监控、分析系统性能 -转载

    原帖地址:http://blog.itpub.net/23135684/viewspace-626439/ 谢谢原帖大人 一.下载nmon. 根据CPU的类型选择下载相应的版本:http://nmon ...

  9. iOS: 在代码中使用Autolayout (2) – intrinsicContentSize和Content Hugging Priority【转】

    原文:http://www.mgenware.com/blog/?p=491 接上文:iOS: 在代码中使用Autolayout (1) – 按比例缩放和优先级. 我们继续来看在代码中使用Autola ...

  10. Swift - 使用CoreLocation实现定位(经纬度、海拔、速度、距离等)

    CoreLocation是iOS中一个提供设备定位的框架.通过这个框架可以实现定位处理,从而获取位置数据,比如经度.纬度.海拔信息等.   1,定位精度的设置 定位服务管理类CLLocationMan ...