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. Codeforces 538E Demiurges Play Again(博弈DP)

    http://codeforces.com/problemset/problem/538/E 题目大意: 给出一棵树,叶子节点上都有一个值,从1-m.有两个人交替从根选择道路,先手希望到达的叶子节点尽 ...

  2. windows下的用户态调试的底层与上层实现

    操作系统:windows XP 调试器通过CreateProcess传入带有DEBUG_PROCESS和DEBUG_ONLY_THIS_PROCESS的dwCreationFlags创建被调试进程.这 ...

  3. Linux 让进程在后台可靠运行的几种方法

    我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败.如何让命令提交后不受本地关闭终端窗口/网络断开 ...

  4. Decimal

    Description 任意一个分数都是有理数,对于任意一个有限小数,我们都可以表示成一个无限循环小数的形式(在其末尾添加0),对于任意一个无限循环小数都可以转化成一个分数.现在你的任务就是将任意一个 ...

  5. Java Spring各种依赖注入注解的区别

    Spring对于Bean的依赖注入,支持多种注解方式: @Resource javax.annotation JSR250 (Common Annotations for Java) @Inject ...

  6. Java 微服务框架 Redkale 入门介绍

    Redkale 功能 Redkale虽然只有1.xM大小,但是麻雀虽小五脏俱全.既可作为服务器使用,也可当工具包使用.作为独立的工具包提供以下功能:1.convert包提供JSON的序列化和反序列化功 ...

  7. iOS7状态栏字体颜色修改

    iOS7中,默认的状态栏字体颜色是黑色的,如何修改为其它颜色呢? 1.在项目的*info.plist中增加 View controller-based status bar appearance 属性 ...

  8. tab切换jquery代码

    http://immmmm.com/jquery-tab-switch-code-improved.html html <div id="sidebar-tab">   ...

  9. (转)A drop-in universal solution for moving text fields out of the way of the keyboard

    There are a hundred and one proposed solutions out there for how to move UITextField andUITextView o ...

  10. 在线C语言编译器/解释器

    在线C语言编译器/解释器 本文介绍两个C语言在线解释器/编译器,这些工具可以提高代码片段检测方便的工作效率,并可以保证这些代码的正确性,而且还可以和别人一起编辑/分享之间的代码,这样可以共同分析代码并 ...