http://codeforces.com/problemset/problem/509/F

题目大意:给出一个遍历树的程序的输出的遍历顺序b序列,问可能的树的形态有多少种。

思路:记忆化搜索

其中我们枚举第一个子树的大小,然后后面的其他子树可以继续分解。

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
#define ll long long
const ll Mod=;
int a[];
ll f[][];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
ll dfs(int l,int r){
if (l>=r){
return (f[l][r]=);
}
if (f[l][r]!=-){
return f[l][r];
}
ll res=;
for (int i=l+;i<=r;i++)
if (i==r||a[l+]<a[i+])
{
res=(res+((dfs(l+,i)*dfs(i,r)))%Mod)%Mod;
}
return f[l][r]=res;
}
int main(){
int n=read();
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
f[i][j]=-;
for (int i=;i<=n;i++) a[i]=read();
printf("%I64d\n",dfs(,n));
return ;
}

Codeforces 509F Progress Monitoring的更多相关文章

  1. Codeforces 509F Progress Monitoring:区间dp【根据遍历顺序求树的方案数】

    题目链接:http://codeforces.com/problemset/problem/509/F 题意: 告诉你遍历一棵树的方法,以及遍历节点的顺序a[i],长度为n. 问你这棵树有多少种可能的 ...

  2. [CF509F]Progress Monitoring

    题目大意: 给定一个树的DFS序$b_1,b_2,\ldots,b_n$($b$为$1\sim n$的一个排列且$b_1=1$).同一个结点的子结点按照结点编号从小到大遍历.问有多少种可能的树的形态? ...

  3. Resumable Media Uploads in the Google Data Protocol

    Eric Bidelman, Google Apps APIs team February 2010 Introduction The Resumable Protocol Initiating a ...

  4. JDK下sun.net.www.protocol.http.HttpURLConnection类-----Http客户端实现类的实现分析

    HttpClient类是进行TCP连接的实现类, package sun.net.www.http; import java.io.*; import java.net.*; import java. ...

  5. list utilities监视数据库前滚操作

    您可以使用 db2pd 或 LIST UTILITIES 命令来监视数据库前滚操作的进度. 过程 发出 LIST UTILITIES 命令并指定 SHOW DETAIL 参数 db2 LIST UTI ...

  6. (转)Db2 备份恢复性能问题诊断与调优

    原文:https://www.ibm.com/developerworks/cn/analytics/library/ba-lo-backup-restore-performance-issue-ju ...

  7. 2017.10.30 Epicor -ERP

    1 公司新用ERP系统,做使用培训,mark... This course reviews the project management flow in the Epicor application. ...

  8. ora_tool

    #!/bin/ksh # # Copyright (c) 1998, 2002, Oracle Corporation.  All rights reserved. #   version() {   ...

  9. 转 Monitoring Restore/Recovery Progress

    ora-279 是可以忽略的报错 In general, a restore should take approximately the same time as a backup, if not l ...

随机推荐

  1. 【Xamarin 开发 IOS --IOS 页面导航概念Segue】

    Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom 一.视图切换类型介绍在storyboard中,segue有几种不同的类型, ...

  2. Java Access Levels(访问控制)

    Access Levels Modifier Class Package Subclass World public Y Y Y Y protected Y Y Y N no modifier Y Y ...

  3. global.asax?app.config?webconfig??

    一.Global.asax 1.global.asax是什么? 一个文本文件,至于它包含写什么内容?顾名思义,global 肯定是掌管一个应用程序(application)的全局性的东西,例如应用程序 ...

  4. oracle数据库 ORA-12560: 协议适配器错误

    ORA-12560:  协议适配器错误 造成ORA-12560: TNS: 协议适配器错误的问题的原因有三个: 1.监听服务没有起起来.windows平台个一如下操作:开始---程序---管理工具-- ...

  5. struts配置,略记

    <!-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener ...

  6. Makefile学习(二)条件判断和内嵌函数

    第七章:Makefile的条件执行 条件语句可是是两个不同的变量.或者变量和常量值的比较: 7.1例子: 对变量“CC”进行判断,其值如果是“gcc ”那么在程序连接时使用库“libgnu.so”或者 ...

  7. 关于C语言中的inline

    在c中,为了解决一些频繁调用的小函数大量消耗栈空间或是叫栈内存的问题,特别的引入了inline修饰符,表示为内联函数.栈空间就是指放置程式的局部数据也就是函数内数据的内存空间,在系统下,栈空间是有限的 ...

  8. MyEclipse 安装activiti designer

    下载activiti designer 文件地址:http://activiti.org/designer/archived/ 注意:我的是myeclipse9.0,我下载的版本是:(当我下载高版本安 ...

  9. mysql连接提示1030

    今天上午,开发使用工具连上mysql,连接一个库,就提示 mysql 错误 ERROR 1030 Got error 28 from. 查询资料,说可能是磁盘空间不足.果然连上去一看/分区空间只有数十 ...

  10. CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27

    CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27   说明:   操作系统:CentOS 6.8 32位 准备篇: 一.系统约定    软件源代码包存放位 ...