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. simulate windows postmessage or keydown

    2 ways: 1. under TForm:   if assigned(focused) then      Focused.keydown(key,keychar,[]); 2. using s ...

  2. 从Lumia退役看为什么WP走向没落(从程序员与市场开发的角度,讲的真棒!)

    http://www.cnblogs.com/zhangkai2237/p/4856880.html

  3. 【操作系统】进程间通信(C#)

    原文:[操作系统]进程间通信(C#) 08年9月入学,12年7月毕业,结束了我在软件学院愉快丰富的大学生活.此系列是对四年专业课程学习的回顾,索引参见:http://blog.csdn.net/xia ...

  4. 【转】Excel快捷键大全

    原文网址:http://www.bm8.com.cn/keyboard/excel.asp 显示和使用"Office 助手"注意 若要执行以下操作,"Microsoft ...

  5. MVC几个系统常用的Filter过滤器

    1.AcceptVerbs 规定页面的访问形式,如 [AcceptVerbs(HttpVerbs.Post)] public ActionResult Example(){ return View() ...

  6. Chrome浏览器查看cookie

    原文:http://jingyan.baidu.com/article/6b18230954dbc0ba59e15960.html 1. 查看页面的cookie 方法: a). 点击地址栏前面的文档薄 ...

  7. jQuery 之$.proxy() 方法

    定义和用法 $.proxy 方法接受一个已有的函数,并返回一个带特定上下文的新的函数. 该方法通常用于向上下文指向不同对象的元素添加事件. 参数 描述 function 要被调用的已有的函数. con ...

  8. Arcgis for js载入天地图

    综述:本节讲述的是用Arcgis for js载入天地图的切片资源. 天地图的切片地图能够通过esri.layers.TiledMapServiceLayer来载入.在此将之进行了一定的封装,例如以下 ...

  9. [RxJS] Creating Observable From Scratch

    Get a better understanding of the RxJS Observable by implementing one that's similar from the ground ...

  10. [Regular Expressions] Find Plain Text Patterns

    The simplest use of Regular Expressions is to find a plain text pattern. In this lesson we'll look a ...