CF 9D. How many trees?(dp)
以前做过类似的,USACO,2.3,开始数组开小了,导致数据乱了,然后超数据范围了,。。
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
#define LL __int64
LL dp[][][];
LL c[][];
int main()
{
int i,j,n,k,u,h;
for(i = ; i <= ; i ++)
{
c[i][] = ;
}
for(i = ; i <= ; i ++)
{
for(j = ; j <= ; j ++)
c[i][j] = c[i-][j-] + c[i-][j];
}
dp[][][] = ;
scanf("%d%d",&n,&h);
for(i = ; i < n; i ++)
{
for(j = ; j <= n; j ++)
{
for(k = ; k <= n; k ++)
{
if(dp[i][j][k] == ) continue;
for(u = ; u <= *k; u ++)
dp[i+][j+u][u] += c[*k][u]*dp[i][j][k];
}
}
}
LL ans = ;
for(i = h; i <= n; i ++)
{
for(k = ; k <= n; k ++)
{
ans += dp[i][n][k];
}
}
printf("%I64d\n",ans);
return ;
}
CF 9D. How many trees?(dp)的更多相关文章
- Codeforces 9D How many trees? 【计数类DP】
Codeforces 9D How many trees? LINK 题目大意就是给你一个n和一个h 问你有多少个n个节点高度不小于h的二叉树 n和h的范围都很小 感觉有无限可能 考虑一下一个很显然的 ...
- CF 983B XOR-pyramid(区间dp,异或)
CF 983B XOR-pyramid(区间dp,异或) 若有一个长度为m的数组b,定义函数f为: \(f(b) = \begin{cases} b[1] & \quad \text{if } ...
- Codeforces - 9D - How many trees? - 简单dp - 组合数学
https://codeforces.com/problemset/problem/9/D 一开始居然还想直接找公式的,想了想还是放弃了.原来这种结构是要动态规划. 状态是知道怎么设了,$t_{nh} ...
- 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 ...
随机推荐
- Delphi中uses在interfeace和implementation中的区别
use单元引入分为在interface中引入,如 interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Co ...
- Pyqt 屏幕截图工具
从Pyqt的examples中看到一段截图代码, (路径:examplas\desktop\screenshot.py) 所以想自己UI下界面,手动练习下 通过UI生成的: Screenshot.py ...
- python中如何用dis模块来查看py的汇编代码?
之前测试不成功,用导入dis的方式. 但如何在命令行里加入 -m dis,就会OK啦. python -m dis test.py #coding: utf8 x = [1, 2, 3] for i ...
- JavaScript中判断对象类型方法大全2
在JavaScript中,有5种基本数据类型和1种复杂数据类型,基本数据类型有:Undefined, Null, Boolean, Number和String:复杂数据类型是Object,Object ...
- Solr入门之(8)中文分词器配置
Solr中虽然提供了一个中文分词器,但是效果很差,可以使用IKAnalyzer或Mmseg4j 或其他中文分词器. 一.IKAnalyzer分词器配置: 1.下载IKAnalyzer(IKAnalyz ...
- wp8 入门到精通 虚拟标示符 设备ID
//获得设备虚拟标示符 wp8 public string GetWindowsLiveAnonymousID() { object anid = new object(); string anony ...
- 来访统计的JS代码
<script language="JavaScript"> var caution = false function setCookie(name, value, e ...
- linux 读写锁应用实例
转自:http://blog.csdn.net/dsg333/article/details/22113489 /*使用读写锁实现四个线程读写一段程序的实例,共创建了四个新的线程,其中两个线程用来读取 ...
- android selector(转)
Selector的结构描述: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:a ...
- Vijos P1459 车展 treap求任意区间中位数
描述 遥控车是在是太漂亮了,韵韵的好朋友都想来参观,所以游乐园决定举办m次车展.车库里共有n辆车,从左到右依次编号为1,2,…,n,每辆车都有一个展台.刚开始每个展台都有一个唯一的高度h[i].主管已 ...