这题我想了好久

设 \(f_{i,j}\) 为 \(i\) 结点 \(<=j\) 的方案数

固定根,枚举左右子树,就有:

\[f_{i,j}=\sum_{k=0}^{n-1}f_{k,j-1}*f_{i-k-1,j-1}
\]

初始化 \(f_{0,i}=1\)

答案 \(ans=f_{n,n}-f_{n,h-1}\)

Code

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define N 40
#define int long long
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
int n,h;
int f[N][N]; //f[i][j] 表示 i个结点 高度为j 的方案总数
signed main()
{
n = read(), h = read();
for(int i=0;i<=n;++i)
f[0][i] = 1;
for(int j=1;j<=n;++j)
for(int i=1;i<=n;++i)
for(int k=0;k<i;++k)
f[i][j] += f[k][j-1]*f[i-k-1][j-1];
cout<<f[n][n]-f[n][h-1]<<endl;
return 0;
}

CF9D How many trees? (dp)的更多相关文章

  1. Codeforces Round #369 (Div. 2) C. Coloring Trees DP

    C. Coloring Trees   ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the pa ...

  2. CodeForces #369 C. Coloring Trees DP

    题目链接:C. Coloring Trees 题意:给出n棵树的颜色,有些树被染了,有些没有.现在让你把没被染色的树染色.使得beauty = k.问,最少使用的颜料是多少.   K:连续的颜色为一组 ...

  3. C. Coloring Trees DP

    传送门:http://codeforces.com/problemset/problem/711/C 题目: C. Coloring Trees time limit per test 2 secon ...

  4. codeforces 711C C. Coloring Trees(dp)

    题目链接: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. BC.5200.Trees(dp)

    Trees  Accepts: 156  Submissions: 533  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/6 ...

  6. D. How many trees? DP

    D. How many trees? time limit per test 1 second memory limit per test 64 megabytes input standard in ...

  7. Codeforces 677C. Coloring Trees dp

    C. Coloring Trees time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  8. Codeforces Beta Round #9 (Div. 2 Only) D. How many trees? dp

    D. How many trees? 题目连接: http://www.codeforces.com/contest/9/problem/D Description In one very old t ...

  9. CF 9D. How many trees?(dp)

    题目链接 以前做过类似的,USACO,2.3,开始数组开小了,导致数据乱了,然后超数据范围了,.. #include <cstdio> #include <iostream> ...

随机推荐

  1. onchange and oninput

    https://www.w3schools.com/jsref/event_oninput.asp Supported HTML tags: <input type="color&qu ...

  2. 源码编译安装Apache/2.4.37-------踩了无数坑,重装了十几次服务器才会的,不容易啊!

    1.先进入/usr/local/中创建三个文件夹 apr apr-util apache cd /usr/local目录 mkdir apr mkdir apr-util mkdir apache 2 ...

  3. lazarus 2016 2月18 4:22:35 支持android开发了, 既ios,linux,macosx,window,web 后 囊括一切啦。 哈哈

    Android Development Lazarus for Linux Lazarus for Mac OS X Lazarus for iOS Lazarus for Windows Lazar ...

  4. new Date() 对象及方法:

    在别人的代码中见了两回 new Date().toLocaleString(),查了才知道,toLocaleString()是 根据本地时间格式,把 Date 对象转换为字符串.于是好奇new Dat ...

  5. sql中的isnull

    ISNULL 使用指定的替换值替换 NULL. 语法ISNULL ( check_expression , replacement_value ) 参数check_expression 将被检查是否为 ...

  6. SQL复制远程数据库数据到本地-及查询结果少显示一列

    网上找了查询结果怎么少显示一列,因为数据很多列,结果不是视图就是嵌套,太麻烦,这里用临时表做 exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB', '19 ...

  7. [Git] 011 checkout 与 reset 命令的补充

    1. git checkout -- <file> 的示意 2. "checkout" 的补充 2.1 git checkout <branch_name> ...

  8. Java枚举enum关键字

    枚举的理解 枚举其实就是一个类,枚举类的实例是一组限定的对象 传统的方式创建枚举 [了解] 对比:单例类 1.构造器私有化 2.本类内部创建对象 3.通过public static方法,对外暴露该对象 ...

  9. java类从加载、连接到初始化过程

    类加载器 在了解Java的机制之前,需要先了解类在JVM(Java虚拟机)中是如何加载的,这对后面理解java其它机制将有重要作用. 每个类编译后产生一个Class对象,存储在.class文件中,JV ...

  10. 针对【H-2017年信息基础班(周一班)】某些同学恶意使用lyl洛谷的谴责

    我在此发表针对 2019-04-01 17:38 某些hsy班同学恶意使用lyl账号的强烈谴责,望自重!! 以下为证据: 传送门