codeforces9D How many trees?
传送门: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?的更多相关文章
- 『题解』Codeforces9D How many trees?
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description In one very old text file there was wr ...
- [C#] C# 知识回顾 - 表达式树 Expression Trees
C# 知识回顾 - 表达式树 Expression Trees 目录 简介 Lambda 表达式创建表达式树 API 创建表达式树 解析表达式树 表达式树的永久性 编译表达式树 执行表达式树 修改表达 ...
- hdu2848 Visible Trees (容斥原理)
题意: 给n*m个点(1 ≤ m, n ≤ 1e5),左下角的点为(1,1),右上角的点(n,m),一个人站在(0,0)看这些点.在一条直线上,只能看到最前面的一个点,后面的被档住看不到,求这个人能看 ...
- [LeetCode] Minimum Height Trees 最小高度树
For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- 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 ...
- 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 ...
- Christmas Trees, Promises和Event Emitters
今天有同事问我下面这段代码是什么意思: var MyClass = function() { events.EventEmitter.call(this); // 这行是什么意思? }; util.i ...
随机推荐
- grep文本处理工具
grep是一款文本过滤工具,基于正则表达式进行模式匹配sed:stream editor 流编辑器awk:linux上实现为gawk,文本报告生成器(格式化文本)文本搜索工具,根据用户指定的模式,对目 ...
- Cannot open the disk 'D:\win7-ie8\Windows 7 x64.vmdk' or one of the snapshot
使用机子过程中断电,开机后使用虚拟机提示[Cannot open the disk 'D:\win7-ie8\Windows 7 x64.vmdk' or one of the snapshot],找 ...
- Print Nodes in Top View of Binary Tree
Top view of a binary tree is the set of nodes visible when the tree is viewed from the top. Given a ...
- 关于Delphi内存表的使用说明
关于Delphi内存表的使用说明: 1.建立临时表 数据输入是开发数据库程序的必然环节.在Client/Server结构中,客户端可能要输入一批数据后,再向服务器的后台数据库提交,这就需要在本地(客 ...
- Java8 新特性Stream 的学习和使用方法
流(Stream) 流是java 8 中新引入的特性,用来处理集合中的数据,Stream 是一个来自数据源的元素队列并支持聚合操作. Java 中 Stream 不会存储元素. 数据源 流的来源. 可 ...
- 【HDU5469】Antonidas(点分治,字符串哈希)
[HDU5469]Antonidas(点分治,字符串哈希) 题面 HDU Vjudge 题解 啊哈?什么垃圾一眼点分治+Hash判断,哈哈哈哈哈,让我来码码码. 诶,怎么WA了.改改改改改. 诶,怎么 ...
- BZOJ 1014 火星人 | 平衡树维护哈希
BZOJ 1014 火星人 题意 有一个字符串,三中操作:在某位置后面插入一个字符.修改某位置的字符.询问两个后缀的最长公共前缀. 题解 看到网上的dalao们都说这道题是平衡树,我就很懵x--平衡树 ...
- Fork/Join框架实现原理
ForkJoinPool由ForkJoinTask数组和ForkJoinWorkerThread数组组成,ForkJoinTask数组负责存放程序提交给ForkJoinPool的任务,而ForkJoi ...
- sqlmap利用DNS进行oob(out of band)注入(转)
0x00 起因 实际案子的时候遇到了一个注入,过狗可以使用sqlmap,但是是基于时间的注入和限制频率需要使用--delay参数,本来就是延时再加上--delay等的心力憔悴.所有有了下面介绍使用 ...
- java之初学线程
线程 学习线程相关的笔记,前面写过关于很多线程的使用,有兴趣的可以去了解下 线程 概念理解 并发 : 指两个或多个事件在同一个时间段内发生(交替执行). 并行 : 指两个或多个事件在同一时刻发生(同时 ...