传送门:http://codeforces.com/problemset/problem/9/D

【题解】

树形dp,f(i,j)表示i个节点,高度为j的方案数,枚举左子树大小和哪一个子树高度为j-1即可。

不加任何优化时间复杂度$O(n^4)$

 # include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int M = ; int n, h;
ll f[M][M]; int main() {
cin >> n >> h;
f[][] = ;
for (int i=; i<=n; ++i)
for (int j=; j<=i; ++j) {
for (int k=; k<=i-; ++k)
for (int l=; l<=j-; ++l)
f[i][j] += f[k][j-]*f[i-k-][l];
for (int k=; k<=i-; ++k)
for (int l=; l<=j-; ++l)
f[i][j] += f[k][j-]*f[i-k-][l];
}
ll ans = ;
for (int i=h; i<=n; ++i) ans += f[n][i];
cout << ans;
return ;
}

codeforces9D How many trees?的更多相关文章

  1. 『题解』Codeforces9D How many trees?

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description In one very old text file there was wr ...

  2. [C#] C# 知识回顾 - 表达式树 Expression Trees

    C# 知识回顾 - 表达式树 Expression Trees 目录 简介 Lambda 表达式创建表达式树 API 创建表达式树 解析表达式树 表达式树的永久性 编译表达式树 执行表达式树 修改表达 ...

  3. hdu2848 Visible Trees (容斥原理)

    题意: 给n*m个点(1 ≤ m, n ≤ 1e5),左下角的点为(1,1),右上角的点(n,m),一个人站在(0,0)看这些点.在一条直线上,只能看到最前面的一个点,后面的被档住看不到,求这个人能看 ...

  4. [LeetCode] Minimum Height Trees 最小高度树

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...

  5. [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  6. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

  7. 2 Unique Binary Search Trees II_Leetcode

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

  8. Finger Trees: A Simple General-purpose Data Structure

    http://staff.city.ac.uk/~ross/papers/FingerTree.html Summary We present 2-3 finger trees, a function ...

  9. Christmas Trees, Promises和Event Emitters

    今天有同事问我下面这段代码是什么意思: var MyClass = function() { events.EventEmitter.call(this); // 这行是什么意思? }; util.i ...

随机推荐

  1. Scrum 项目4.0&&5.0

    MY—HR 成员: 角色分配 学号 博客园 4.0团队贡献分 5.0团队贡献分 丘惠敏 PM项目经理 201406114203 http://www.cnblogs.com/qiuhuimin/ 19 ...

  2. LeetCode题解:(221) Maximal Square

    题目说明 Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's a ...

  3. 初期测评 A 排序

    https://vjudge.net/contest/240302#problem/A 输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0 ...

  4. js+Canvas 利用js 实现浏览器保存图片到本地

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. 最近JavaScript的一些收获

    开发习惯的上的收获 1,开发过程中,要让整个逻辑展示在一个函数中,中间部分则做可以考虑公用策略优化 2,开发完成至少有三个角度进行测试,正面方面和中立 开发技巧上面的收获 1,驼峰转为‘-’以及‘-’ ...

  6. FastReport 变量列表使用

    使用报表变量时,引用“frxVariables”单元. 变量定义在“TfrxVariable” 类: TfrxVariable = class(TCollectionItem) published p ...

  7. 学习mysql触发器遇到的问题

    在 mysql.exe 下面运行的.如果是的话, 可能是需要加一个 定义 DELIMITER // 意思是告诉 mysql , 遇到 // 符号以后, 才认为语句结束了. 否则 mysql 遇到 分号 ...

  8. webservice(一) 概念

    Web service:是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述.发布.发现.协调和配置这些应用程序,用于开发分 ...

  9. Java 使用 DBCP mysql 连接池 做数据库操作

    需要的jar包有 commons-dbutils , commons-dbcp , commons-pool , mysql-connector-java 本地database.propertties ...

  10. latex添加eps文档

    latex添加图像时,要将.eps文档放在当前文件夹中,然后使用: % For one-column wide figures use\begin{figure}\begin{center}% Use ...