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. hdu 畅通工程

    http://acm.hdu.edu.cn/showproblem.php?pid=1863 #include <cstdio> #include <cstring> #inc ...

  2. 终于懂了:Delphi的函数名不是地址,取地址必须遵守Object Pascal的语法(Delphi和C的类比:指针、字符串、函数指针、内存分配等)good

    这点是与C语言不一样的地方,以前我一直都没有明白这一点,所以总是不明白:函数地址再取地址算怎么回事? ------------------------------------------------- ...

  3. 使用ngrok让微信公众平台通过80端口访问本机

    最近在做微信开发,感觉测试不怎么方便,在网上找了找一下帖子,发现了这个好工具哈,与大家一同分享一下... 原文:http://blog.csdn.net/liuxiyangyang/article/d ...

  4. (greedy)Best Time to Buy and Sell Stock II

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  5. 选择Comparable接口还是Comparator

    个人理解: 如果我本身知道这个类的对象我要用来比较,那么就拿这个类实现Comparable接口(compareTo(Object o) 方法).如果我本身没有预料到我要比较这个类的对象,那么,我可以建 ...

  6. poj 3692 Kindergarten (最大独立集之逆匹配)

    Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...

  7. HTML--控制小人自由移动

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  8. struts1配置文件之input

    <action path="/*Person" type="cn.itcast.PersonAction" scope="request&quo ...

  9. js获取当前页面的网址域名地址

    1.获取当前完整网址thisURL = document.URL;thisHREF = document.location.href;thisSLoc = self.location.href;thi ...

  10. Linux下oracle 11g安装

    服务器环境要求     硬盘 20G以上 ,必须高于1G的物理内存,交换空间一般为内存的2倍,例如:1G的内存可以设置swap 分区为3G大小   在Root用户下执行以下步骤: 修改用户的SHELL ...