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. 封装自己的getClass

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. javascript飞机大战-----004创建子弹对象

    /* 创建子弹:因为子弹不是只创建一个所以要用构造函数 注意一点:子弹发射的位置应该是英雄机的正中央的位置,所以需要传点东西进来 */ function Bullet(l,t){ this.l = l ...

  3. flask的session用法2

    from flask import Flask, session, redirect, url_for, escape, request app = Flask(__name__) @app.rout ...

  4. nginx中获取真实ip(转)

    原文:http://blog.csdn.net/a936676463/article/details/8961504 server { listen       80; server_name  lo ...

  5. Git学习-->关于Jenkins编译时候,如何获取Git分支的当前分支名?

    一.背景 因为代码都迁移到了Gitlab,所以Jenkins编译的时候我们都需要将之前的SVN信息换成现在的Git信息.最近编译一个Lib库的时候,因为团队规定上传Release版本的AAR到Mave ...

  6. Navicat运行sql文件报错out of memory

    下载并安装mysql workbench:

  7. Spring源码解析(三)BeanDefinition的载入、解析和注册

    通过上一篇源码的分析已经完成了BeanDefinition资源文件的定位,本篇继续分析BeanDefinition资源文件的载入和解析. AbstractBeanDefinitionReader的lo ...

  8. Shader工具

    1. RenderMonkey 2. NVIDIA FX Composer 2.5

  9. HDU5139:Formula(找规律+离线处理)

    http://acm.hdu.edu.cn/showproblem.php?pid=5139 Problem Description f(n)=(∏i=1nin−i+1)%1000000007You ...

  10. cocos代码研究(11)ActionManager类学习笔记

    理论部分 ActionManager是一个单例类,管理所有动作. 通常你不需要直接使用这个类.大多情况下,你将使用Node的接口,它提供了更友好的封装 但也有一些情况下,你可能需要使用这个单例. 示例 ...