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

思路:
  树形DP。
  用$f[l][r]$标示DFS序$b_{l\sim r}$对应多少种树的形态。显然当$l=r$时,$f[l][r]=1$。转移方程为$f[l][r]=\sum_{l<m\le r且b_{m+1}<b_{l+1}}f[l+1][m]\times f[m][r]$。其中$f[l+1][m]$表示$b_{l+1\sim m}$构成树的方案数,$f[m][r]$表示$b_{m+1\sim r}$构成森林的方案数。这是一个$2D/1D$的动态规划,时间复杂度$O(n^3)$。

 #include<cstdio>
#include<cctype>
typedef long long int64;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=,mod=1e9+;
int b[N],f[N][N];
int dfs(const int &l,const int &r) {
if(f[l][r]) return f[l][r];
if(l==r) return f[l][r]=;
for(register int m=l+;m<=r;m++) {
if(m!=r&&b[l+]>b[m+]) continue;
(f[l][r]+=(int64)dfs(l+,m)*dfs(m,r)%mod)%=mod;
}
return f[l][r];
}
int main() {
const int n=getint();
for(register int i=;i<=n;i++) b[i]=getint();
printf("%d\n",dfs(,n));
return ;
}

[CF509F]Progress Monitoring的更多相关文章

  1. Codeforces 509F Progress Monitoring

    http://codeforces.com/problemset/problem/509/F 题目大意:给出一个遍历树的程序的输出的遍历顺序b序列,问可能的树的形态有多少种. 思路:记忆化搜索 其中我 ...

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

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

  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. Switf与OC混合开发流程

    看着身边越来越多的小伙伴转入Swift,本人也跟随潮流,转战Swift了~下面是初步写入的一个Swift项目框架. 1.创建项目,这个应该不用说了,语言swift 2.CocoaPods 导入第三方 ...

  2. Java并发(6)- CountDownLatch、Semaphore与AQS

    引言 上一篇文章中详细分析了基于AQS的ReentrantLock原理,ReentrantLock通过AQS中的state变量0和1之间的转换代表了独占锁.那么可以思考一下,当state变量大于1时代 ...

  3. 河南省第十届省赛 Intelligent Parking Building

    title: Intelligent Parking Building 河南省第十届省赛 tags: [模拟,省赛] 题目描述: There is a new revolution in the pa ...

  4. 硬币问题 tarjan缩点+DP 莫涛

    2013-09-15 20:04 题目描述 有这样一个游戏,桌面上摆了N枚硬币,分别标号1-N,每枚硬币有一个分数C[i]与一个后继硬币T[i].作为游戏参与者的你,可以购买一个名为mlj的小机器人, ...

  5. javascript批量输入表单

    void((function(){ x=document.getElementsByTagName("a"); y = x[1] y.click() })()) void((fun ...

  6. django返回二进制图片

    @login_required def down_img(request, path): content = Storage().download(path) from django.http imp ...

  7. python基础代码(猜年龄、从最内层跳出多层循环、简单的购物车程序)

    1.猜年龄 , 可以让用户最多猜三次! age = 55 i=0 while i<3: user_guess = int (input ("input your guess:" ...

  8. 进一步认识golang中的并发

    如果你成天与编程为伍,那么并发这个名词对你而言一定特别耳熟.需要并发的场景太多了,例如一个聊天程序,如果你想让这个聊天程序能够同时接收信息和发送信息,就一定会用到并发,无论那是什么样的并发. 并发的意 ...

  9. [Leetcode Week7]Jump Game

    Jump Game 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/jump-game/description/ Description Given a ...

  10. Swift : missing argument label 'xxx' in call

    http://stackoverflow.com/questions/24050844/swift-missing-argument-label-xxx-in-call up vote37down v ...