区间dp,枚举走完第一个子树之后回到根节点的位置。

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mod=1e9;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
char s[mxn];
int f[mxn][mxn];
int main(){
int i,j;
while(scanf("%s",s+)!=EOF){
int n=strlen(s+);
memset(f,,sizeof f);
for(i=;i<=n;i++)f[i][i]=;
for(int st=;st<=n;st++){
for(i=;i<=n;i++){
j=i+st-;if(j>n)break;
if(s[i]==s[j]){
for(int k=i+;k<=j;k++){
if(s[k]==s[i]){
f[i][j]=((long long)f[i][j]+((long long)f[i+][k-]*f[k][j])%mod)%mod;
}
}
}
}
}
printf("%d\n",f[][n]);
}
return ;
}

UVa1362 Exploring Pyramids的更多相关文章

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

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

  2. LA3516 Exploring Pyramids

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

  3. UVA 1362 Exploring Pyramids 区间DP

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

  4. Gym 101334E Exploring Pyramids(dp+乘法原理)

    http://codeforces.com/gym/101334 题意: 给出一棵多叉树,每个结点的任意两个子节点都有左右之分.从根结点开始,每次尽量往左走,走不通了就回溯,把遇到的字母顺次记录下来, ...

  5. 101334E Exploring Pyramids

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

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

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

  7. LA 3516 - Exploring Pyramids

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  8. LA 3516 Exploring Pyramids (记忆化搜索)

    题意 给定一个DFS序列,问能有多少树与之对应. 思路 设输入序列为S,dp(i, j)为子序列Si, Si+1, --, Sj对应的树的个数,则边界条件为d(i, i) = 1,且Si != Sj时 ...

  9. LA 3516 (计数 DP) Exploring Pyramids

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

随机推荐

  1. UIPopoverController

    if (popOver == nil) { popOver = [[UIPopoverController alloc] initWithContentViewController:viewVC]; ...

  2. 【Python学习之六】高阶函数2(map、reduce、filter、sorted)

    3.filter filter()也接收一个函数和一个序列.和map()不同的是,filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素.相当于一 ...

  3. 【windows】【md5】查看文件的md5值

    certutil -hashfile filename MD5 certutil -hashfile filename SHA1 certutil -hashfile filename SHA256 ...

  4. java上传附件,批量下载附件(一)

    上传附件代码:借助commons-fileupload-1.2.jar package com.str; import java.io.BufferedInputStream;import java. ...

  5. 水题:UVa133-The Dole Queue

    The Dole Queue Time limit 3000 ms Description In a serious attempt to downsize (reduce) the dole que ...

  6. winServer08上安装SQL时提示“必须使用管理角色安装”或配置microsoft.net framework 3.5

    server 2008安装vs2008后报错,如图: 解决方法: 控制面板—>程序—>打开或关闭Windows功能—>进入服务器管理器选择功能—>添加功能 然后勾选.NET F ...

  7. golang导出excel(excel格式)

    之前写过一篇导出cvs格式的,如果只是简单导出完全能满足需要.按时如果想要有复杂需求,如样式定制.多个sheet之类的,就无法完成了.之后发现有人已经实现golang直接excel对excel的操作, ...

  8. alex 推荐的书

     这两本书不错, 追风筝的人<白鹿原>~~~反天不错~~~可以看下.14:27:22AndyZhang 2018-1-29 14:27:22 改变人的东西  读书.看电影.旅行.经历各种事 ...

  9. Hive学习笔记(四)-- hive的桶表

    桶表抽样查询 查看hdfs上对应的文件内容 一个两个桶,第一个桶和第三个桶的数据 task = 4 4 / 2 = 2,一共是两个桶 第1个桶,第1+2个桶

  10. 实现类似QQ单一账户登录,在另一个地方登录后在原登录窗口提示下线

    首先,使用框架做的最好,可以在框架页直接做一次就好了 再登陆成功后保存session的代码后添加以下代码: 注意:需要引入命名空间using System.Collections; SetApplic ...