http://codeforces.com/gym/101334

题意:

给出一棵多叉树,每个结点的任意两个子节点都有左右之分。从根结点开始,每次尽量往左走,走不通了就回溯,把遇到的字母顺次记录下来,可以得到一个序列。

思路:
d【i】【j】表示i~j的序列所对应的子树。

边界条件就是d【i】【i】=1。

每次可以分为两个分支:d【i+1】【k-1】和d【k】【j】。

递归求解。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF=0x3f3f3f3f3f;
const int maxn=+; const int MOD=; char str[maxn];
ll d[maxn][maxn]; ll dp(int i,int j)
{
if(d[i][j]!=-) return d[i][j];
if(i==j) return d[i][j]=;
if(str[i]!=str[j]) return d[i][j]=; d[i][j]=; for(int k=i+;k<=j;k++)
{
if(str[i]==str[k] && str[k]==str[j])
d[i][j]=(d[i][j]+dp(i+,k-)*dp(k,j))%MOD;
}
return d[i][j];
} int main()
{
freopen("exploring.in","r",stdin);
freopen("exploring.out","w",stdout);
//freopen("D:\\input.txt","r",stdin);
while(~scanf("%s",&str))
{
memset(d,-,sizeof(d));
int len=strlen(str);
printf("%lld\n",dp(,len-));
}
}

Gym 101334E Exploring Pyramids(dp+乘法原理)的更多相关文章

  1. [Gym 101334E]Exploring Pyramids(区间dp)

    题意:给定一个先序遍历序列,问符合条件的树的种类数 解题关键:枚举分割点进行dp,若符合条件一定为回文序列,可分治做,采用记忆化搜索的方法. 转移方程:$dp[i][j] = \sum {dp[i + ...

  2. 101334E Exploring Pyramids

    传送门 题目大意 看样例,懂题意 分析 实际就是个区间dp,我开始居然不会...详见代码(代码用的记忆化搜索) 代码 #include<iostream> #include<cstd ...

  3. LA 3516(ZOJ 2641) Exploring Pyramids(递推 DP)

    Exploring Pyramids Archaeologists have discovered a new set of hidden caves in one of the Egyptian p ...

  4. LA3516 Exploring Pyramids

    Exploring Pyramids 题目大意:给定一个欧拉序列(即每经过一个点,把这个点加入序列),问有多少种对应的多叉树 序列与树构造对应问题,考虑区间DP dp[i][j]表示序列i...j对应 ...

  5. UVA 1362 Exploring Pyramids 区间DP

    Archaeologists have discovered a new set of hidden caves in one of the Egyptian pyramids. The decryp ...

  6. LA 3516 (计数 DP) Exploring Pyramids

    设d(i, j)为连续子序列[i, j]构成数的个数,因为遍历从根节点出发最终要回溯到根节点,所以边界情况是:d(i, i) = 1; 如果s[i] != s[j], d(i, j) = 0 假设第一 ...

  7. Gym 101334E dp

    分析: 这一题给出的遍历的点的序列,不是树的中序遍历,前序遍历,只要遇到一个节点就打印一个节点.关键点就在,这个序列的首字母和尾字母一定要相同,因为最终都会回到根节点,那么每一个子树也一样. 状态: ...

  8. 【区间dp】【记忆化搜索】UVALive - 3516 - Exploring Pyramids

    f(i,j)=sum(f(i+1,k-1)*f(k,j) | i+2<=k<=j,Si=Sk=Sj). f(i+1,k-1)是划分出第一颗子树,f(k,j)是划分出剩下的子树. #incl ...

  9. Exploring Pyramids UVALive - 3516 (记忆化DP)

    题意:给定一个序列 问有多少棵树与之对应 题目连接:https://cn.vjudge.net/problem/UVALive-3516 对于这一序列  分两种2情况 当前分支 和 其它分支  用df ...

随机推荐

  1. Swift - 触摸事件响应机制(UiView事件传递)

    import UIKit class FatherView: UIView { override func hitTest(point: CGPoint, withEvent event: UIEve ...

  2. 6.IIs部署与发布

    A.网站的发布步骤: 1.首先要选择要发布的网站(即项目里的网站)也就是代码. 2.左键选择发布. 3.配置文件:Web.congig. 4.连接:publis method:File System, ...

  3. 【转】SpringMVC+Spring3+Hibernate4开发环境搭建

    原文地址: SpringMVC+Spring3+Hibernate4开发环境搭建

  4. 【ArcGIS for SivlerLight api(3)】基础图层增删改查

    1.基础底图通常使用TiledLayer或者ArcGISDynamicLayer. 本质上都是在本地加载栅格图片.后台生成策略不同而已.从Vs2010的控件栏上拖过来的Map控件默认添加的底图是Esr ...

  5. centos7 iptables/firewalld docker open port

    here are multiple "hackish" ways to do it: scan kernel logs, as mentioned by Jiri (but you ...

  6. PostgreSQL数据库的安装与PostGIS的安装(转)

    原文:http://lovewinner.iteye.com/blog/1490915 安装postgresql sudo apt-get install postgresql-9.1 postgre ...

  7. 【我的Android进阶之旅】解决sqlcipher库:java.lang.IllegalStateException: get field slot from row 0 col 0 failed.

    一.背景 最近维护公司的大数据SDK,在大数据SDK里面加入了ANR的监控功能,并将ANR的相关信息通过大数据埋点的方式记录到了数据库中,然后大数据上报的时候上报到大数据平台,这样就可以实现ANR性能 ...

  8. 【Linux学习 】Linux使用Script命令来记录并回放终端会话

    一背景 二script命令简介 1 什么script命令 2 script命令操作 21 file选项 22 options选项 23 退出script 三Script命令结合实际使用场景 1 先在终 ...

  9. Mysql varchar 把默认值设置为null和空的区别

    '\0',这个表示空,需要消耗存储空间的.NULL,则表示连这个\0都没有. NULL,你可以近似理解为变量未赋值(定义了变量,但是未使用,变量不指向具体存储空间,因此,理论上不消耗存储空间),同时, ...

  10. eval(PHP 4, PHP 5)

    eval — 把字符串作为PHP代码执行 说明 mixed eval ( string $code_str ) 把字符串 code_str 作为PHP代码执行. 除了其他,该函数能够执行储存于数据库文 ...