传送门: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. 关于对i++,++i的理解

    i++,代表 先赋值,在加:++i,代表先自加再赋值:后台console例子中可以看到第一个例子:var a= i++;  i是等于1的:先赋值,所以打印出a =1的:而i++后为2:所以打印出a = ...

  2. Linux上两种网络连接方式

    模式一:NAT方式好处:路由器更换,或者交换机更换,网络仍然可以使用,所用使用最多 准备工作: 查看VMware服务器启动情况,五个全开模式 vmnet8开启模式 1 配置VMware交换机的ip地址 ...

  3. date format 参数表

    format 必需.规定输出日期字符串的格式.可使用下列字符: d - 一个月中的第几天(从 01 到 31) D - 星期几的文本表示(用三个字母表示) j - 一个月中的第几天,不带前导零(1 到 ...

  4. dividend = Integer.parseInt(args[0])参数问题

    先来一段代码: package yichang; public class MyExceptionTest { public static void main(String[] args) { int ...

  5. 计算机网络【6】—— 从浏览器输入URL到显示页面发生了什么

    当在浏览器地址栏输入网址,如:www.baidu.com后浏览器是怎么把最终的页面呈现出来的呢?这个过程可以大致分为两个部分:网络通信和页面渲染. 一.网络通信 互联网内各网络设备间的通信都遵循TCP ...

  6. SET ANSI_NULLS ON,SET NOCOUNT ON,SET QUOTED_IDENTIFIER ON

    SET ANSI_NULLS ONTransact-SQL 支持在与空值进行比较时,允许比较运算符返回 TRUE 或 FALSE. 通过设置 ANSI_NULLS OFF 可将此选项激活.当 ANSI ...

  7. TeX-换行换页与段落命令

    换行换页与段落命令1 UTF8nsung Abstract 文档在排版时往往要求每一行具有相同的长度, LATEX 为了对整段的文挡进行优化,将插入必要的换行和空恪.如果必要的话对于一行中不好放的单词 ...

  8. CodeForces - 988D(思维STL)

    原文地址:https://blog.csdn.net/weixin_39453270/article/details/80548442 博主已经讲的很好了 题意: 从一个序列中,选出一个集合,使得集合 ...

  9. STL Set和multiset 容器

    STL Set和multiset 容器 set/multiset的简介 set是一个集合容器,其中所包含的元素是唯一的,集合中的元素按一定的顺序排列. 元素插入过程是按排序规则插入,所以不能指定插入位 ...

  10. Udp广播的发送与接收(C#+UdpClient) 上篇

    简介: Udp广播消息用在局域网的消息传递很方便.本文使用UdpClient类在WPF下实现Udp广播收发 发送: void MainWindow_Loaded(object sender, Rout ...