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 ...
随机推荐
- 在ubuntu上搭建开发环境6---安装和使用vim及其插件(Pathogen和NERDTree)
2015.09.08 更为详细的配置vim的方法,请参见我的新整理的文章:http://segmentfault.com/a/1190000003722928 Vim安装 命令: sudo apt-g ...
- 【翻译十九】-java之执行器
Executors In all of the previous examples, there's a close connection between the task being done by ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- windows操作技巧
-------------------win7专有------------------- WIN+上下左右可以将当前窗口 最大化.左侧放置.右侧放置.最小化 WIN+Shift+左右是让窗口在多个屏幕 ...
- 【计算机图形学】openGL常用函数
OpenGL常用函数 glAccum 操作累加缓冲区 glAddSwapHintRectWIN 定义一组被 SwapBuffers拷贝的三角形 glAlphaFunc允许设置alpha检测 ...
- hibernate中many-to-one关联时出现ObjectNotFoundException异常
采用多对一关联,如果一的那端删除了,多的这端无法感知,虽然数据库中可以通过外键配置将多的一端置空,可是在hibernate里面我暂时不知道如何处理. 目前采用的方式: 1.首先,数据库中需要配置好外键 ...
- java 杂物间 (一) Mybatis
这里放置的是一些杂物,生人勿入. Token的一般parse 过程. @Test public void shouldDemonstrateGenericTokenReplacement() { Ge ...
- NS2中修改载波侦听范围和传输范围
修改这两个值是在tcl中进行的,加上 Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#550m Phy/WirelessPhy set RXThresh_ 3.65 ...
- 同一天的时间差,显示为HHMMSS和指定日期时间部分
//1.hhmmss private String setGoodsDisBalance(Date startTime,Date endTime){ //时间差:毫秒ms long diff = en ...
- Reading and Writing CSV Files in C#
Introduction A common requirement is to have applications share data with other programs. Although t ...