CF9D How many trees? (dp)
这题我想了好久
设 \(f_{i,j}\) 为 \(i\) 结点 \(<=j\) 的方案数
固定根,枚举左右子树,就有:
\]
初始化 \(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)的更多相关文章
- 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 ...
- CodeForces #369 C. Coloring Trees DP
题目链接:C. Coloring Trees 题意:给出n棵树的颜色,有些树被染了,有些没有.现在让你把没被染色的树染色.使得beauty = k.问,最少使用的颜料是多少. K:连续的颜色为一组 ...
- C. Coloring Trees DP
传送门:http://codeforces.com/problemset/problem/711/C 题目: C. Coloring Trees time limit per test 2 secon ...
- codeforces 711C C. Coloring Trees(dp)
题目链接: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- BC.5200.Trees(dp)
Trees Accepts: 156 Submissions: 533 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/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 ...
- Codeforces 677C. Coloring Trees dp
C. Coloring Trees time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- 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 ...
- CF 9D. How many trees?(dp)
题目链接 以前做过类似的,USACO,2.3,开始数组开小了,导致数据乱了,然后超数据范围了,.. #include <cstdio> #include <iostream> ...
随机推荐
- Windows 搭建Hadoop 2.7.3开发环境
1.安装配置Java环境 1.1.安装Windows版本的jkd应用程序 当前的系统环境是64位Windows 7,因此下载64位JDK,下载地址:http://download.oracle.com ...
- flask的请求上下文request对象
Flask从客户端收到请求时,要让视图函数能访问请求对象request ,才能处理请求.我们可以将request对象作为参数传到试图函数里,比如: from flask import Flask, r ...
- React-Native 之 GD (十七)小时风云榜按钮处理
小时风云榜按钮处理 在服务器返回给我们的 json 数据中,提供了 hasnexthour 字段,当这个字段返回为 1 的时候,表示后面还有内容,按钮可以点击,否则不能点击,按照这个思路,我们就来完成 ...
- 【洛谷P4445 【AHOI2018初中组】报名签到】
题目描述 n 位同学(编号从1 到n)同时来到体育馆报名签到,领取准考证和参赛资料.为了有序报名,这n 位同学需要按编号次序(编号为1 的同学站在最前面)从前往后排成一条直线.然而每一位同学都不喜欢拥 ...
- accomplish、complete、finish、achieve和fulfill
accomplish to succeed in doing something, especially after trying very hard vt. 完成:实现:达到 complete us ...
- mysql_存储引擎层-innodb buffer pool
buffer pool 是innodb存储引擎带的一个缓存池,查询数据时,首先从内存中查询 数据如果内存中存在的话直接返回. innodb buffer pool 和 qcache 的区别:Qcach ...
- debian sftp/ssh
检查是否安装poenssh dpkg --get-selections | grep openssh 如下表示已经安装
- 阿里云ipv6安全组匹配所有ip的方法
IPv4和IPv6通信彼此独立.您需要为ECS实例单独配置IPv6安全组规则. 操作步骤 登录ECS控制台. 在左侧导航栏,单击网络和安全 > 安全组. 找到目标安全组,然后单击配置规则. 单击 ...
- 《Python Data Structures》Week5 Dictionary 课堂笔记
Coursera课程<Python Data Structures> 密歇根大学 Charles Severance Week5 Dictionary 9.1 Dictionaries 字 ...
- 19c的 rac在oracle linux7.4上搭建总结
准备: 1,ASM磁盘空间最低要求OCR的磁盘占用需求有了明显增长.为了方便操作,设置如下:External: 1个卷x40GNormal: 3个卷x30GHight: 5个卷x25GFlex: 3个 ...