[CF509F]Progress Monitoring
题目大意:
给定一个树的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的更多相关文章
- Codeforces 509F Progress Monitoring
http://codeforces.com/problemset/problem/509/F 题目大意:给出一个遍历树的程序的输出的遍历顺序b序列,问可能的树的形态有多少种. 思路:记忆化搜索 其中我 ...
- Codeforces 509F Progress Monitoring:区间dp【根据遍历顺序求树的方案数】
题目链接:http://codeforces.com/problemset/problem/509/F 题意: 告诉你遍历一棵树的方法,以及遍历节点的顺序a[i],长度为n. 问你这棵树有多少种可能的 ...
- Resumable Media Uploads in the Google Data Protocol
Eric Bidelman, Google Apps APIs team February 2010 Introduction The Resumable Protocol Initiating a ...
- JDK下sun.net.www.protocol.http.HttpURLConnection类-----Http客户端实现类的实现分析
HttpClient类是进行TCP连接的实现类, package sun.net.www.http; import java.io.*; import java.net.*; import java. ...
- list utilities监视数据库前滚操作
您可以使用 db2pd 或 LIST UTILITIES 命令来监视数据库前滚操作的进度. 过程 发出 LIST UTILITIES 命令并指定 SHOW DETAIL 参数 db2 LIST UTI ...
- (转)Db2 备份恢复性能问题诊断与调优
原文:https://www.ibm.com/developerworks/cn/analytics/library/ba-lo-backup-restore-performance-issue-ju ...
- 2017.10.30 Epicor -ERP
1 公司新用ERP系统,做使用培训,mark... This course reviews the project management flow in the Epicor application. ...
- ora_tool
#!/bin/ksh # # Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved. # version() { ...
- 转 Monitoring Restore/Recovery Progress
ora-279 是可以忽略的报错 In general, a restore should take approximately the same time as a backup, if not l ...
随机推荐
- [bzoj 2115]线性基+图论
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2115 给定一个带权无向图,要找出从1到n路径权值异或和最大的那一条的路径异或和. 考虑1到 ...
- Codeforces Round #526 (Div. 2) E. The Fair Nut and Strings
E. The Fair Nut and Strings 题目链接:https://codeforces.com/contest/1084/problem/E 题意: 输入n,k,k代表一共有长度为n的 ...
- JAVA中string.replace()和string.replaceAll()的区别及用法
乍一看,字面上理解好像replace只替换第一个出现的字符(受javascript的影响),replaceall替换所有的字符,其实大不然,只是替换的用途不一样. public String r ...
- java程序在centos7里面开机自启动
1.我们先来个简单的start,status,stop程序: [root@localhost ~]# cat /home/tomcat/jarservice.sh #!/bin/bashCU_PID= ...
- 创建Maven项目出现:An internal error occurred during: "Retrieving archetypes:". Java heap space 错误解决办法
首先说明一下网上的方法: 在Eclipse中创建Maven的Web项目时出现错误:An internal error occurred during: "Retrieving archety ...
- Ubuntu 15.10 安装比特币客户端
下载 git clone https://github.com/bitcoin/bitcoin.git cd bitcoin ./autogen.sh 安装依赖包: ++-dev sudo apt-g ...
- How to learn wxPython
目录 How to learn wxPython Learn Python Choose a good editor Install wxPython Read the wxPython tutori ...
- POJ3180(有向图强连通分量结点数>=2的个数)
The Cow Prom Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1451 Accepted: 922 Descr ...
- (接口自动化)Python3操作MySQL数据库
基础语法: import pymysql #导入模块 conn = pymysql.connect(host='localhost',user='root', passwd='123456', db= ...
- 【bzoj3261】最大异或和
就是一个可持久化Trie....... #include<bits/stdc++.h> #define N 600005 using namespace std; inline int r ...