Easy Tree DP?

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1487    Accepted Submission(s): 567

Problem Description
A Bear tree is a binary tree with such properties : each node has a value of 20,21…2(N-1)(each number used only once),and for each node ,its left subtree’s elements’ sum<its right subtree’s elements’ sum(if the node hasn’t left/right subtree ,this limitation is invalid).
You need to calculate how many Bear trees with N nodes and exactly D deeps.
 
Input
First a integer T(T<=5000),then T lines follow ,every line has two positive integer N,D.(1<=D<=N<=360).
 
Output
For each test case, print "Case #t:" first, in which t is the number of the test case starting from 1 and the number of Bear tree.(mod 109+7)
 
Sample Input
2
2 2
4 3
 
Sample Output
Case #1: 4
Case #2: 72
 
Author
smxrwzdx@UESTC_Brightroar
 
Source

解题:哎。。连续训练了两个月,身累心更累。。不想说什么了,看这位大神的解说吧

他的钻头是可以突破天际的钻头

 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
typedef long long LL;
const LL mod = 1e9 + ;
LL dp[maxn][maxn],c[maxn][maxn];
void init(){
memset(dp,-,sizeof dp);
for(int i = ; i < maxn; ++i){
c[i][] = c[i][i] = ;
for(int j = ; j < i; ++j)
c[i][j] = (c[i-][j-] + c[i-][j])%mod;
}
}
LL dfs(int n,int d){
if(n == && d >= ) return ;
if(n == || d == ) return ;
if(dp[n][d] != -) return dp[n][d];
LL &ret = dp[n][d];
ret = (dfs(n-,d-)*c[n][]*)%mod;
for(int k = ; k <= n-; ++k)
ret = (ret + (dfs(n-k-,d-)*dfs(k,d-)%mod*c[n-][k]%mod*c[n][])%mod)%mod;
return ret;
}
int main(){
int kase,cs = ,n,d;
init();
scanf("%d",&kase);
while(kase--){
scanf("%d%d",&n,&d);
printf("Case #%d: %I64d\n",cs++,(dfs(n,d) - dfs(n,d-) + mod)%mod);
}
return ;
}

HDU 4359 Easy Tree DP?的更多相关文章

  1. HDU 4359——Easy Tree DP?——————【dp+组合计数】

    Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. HDU 4359 Easy Tree DP? 带权二叉树的构造方法 dp

    题意: 给定n deep 1.构造一个n个节点的带权树,且最大深度为deep,每一个节点最多仅仅能有2个儿子 2.每一个节点的值为2^0, 2^1 ··· 2^(n-1)  随意两个节点值不能同样 3 ...

  3. HDU 4359 Easy Tree DP? 组合数学+动归

    题意:定义一种树,每个节点的权值都是20到2n-1,每个权值出现一次,每个节点的左子树的权值和小于右子树,除非只有一个子树.给你n和d,问有n个节点且恰好深度是d的这种树有多少种. 比赛的时候我没有做 ...

  4. HDU 5513 Efficient Tree

    HDU 5513 Efficient Tree 题意 给一个\(N \times M(N \le 800, M \le 7)\)矩形. 已知每个点\((i-1, j)\)和\((i,j-1)\)连边的 ...

  5. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  6. hdu 2296 aC自动机+dp(得到价值最大的字符串)

    Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. 96. Unique Binary Search Trees (Tree; DP)

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  8. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

  9. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

随机推荐

  1. Ant报错之out of memory

    用Ant打包一个比較大的项目的时候,遇到OutOfMemory的问题,求助于Google和百度,网上的解决方式非常多,可是个人认为不够具体全面.我的问题须要综合两种方法才解决.把方案记下来.以期帮助大 ...

  2. C++ Web 编程(菜鸟教程)

    C++ Web 编程(菜鸟教程) C++ Web 编程 什么是 CGI? 公共网关接口(CGI),是一套标准,定义了信息是如何在 Web 服务器和客户端脚本之间进行交换的. CGI 规范目前是由 NC ...

  3. 协同过滤算法中皮尔逊相关系数的计算 C++

    template <class T1, class T2>double Pearson(std::vector<T1> &inst1, std::vector<T ...

  4. Java插入中文到数据库中文变成问号解决

    转自:https://blog.csdn.net/hellosweet1/article/details/81673152 之所以会出现乱码,就是编码方式不一致导致的 我们应该首先确定         ...

  5. Django day17 博客项目(一)

    一: 博客项目需求分析 首页(显示文章) 文章详情 点赞, 点踩 文章评论 字评论 评论的展示 登录功能(图片验证码) 注册功能(基于form验证,ajax) 个人站点(不同人不同样式,文章过滤) 后 ...

  6. 【STM32H7教程】第23章 STM32H7的MPU内存保护单元(重要)

    完整教程下载地址:http://forum.armfly.com/forum.php?mod=viewthread&tid=86980 第23章       STM32H7的MPU内存保护单元 ...

  7. C#发送电子邮件代码记录

    /// <summary> /// 发送电子邮件 /// </summary> /// <param name="Address">邮件地址&l ...

  8. MyEclipse中快速复制粘贴当前行的操作

  9. sql--Truncate Table

    Truncate Table(截断表) 有时候需要清除一个表中的所有资料.要达到者个目的,一种方式是DROP TABLE 指令.不过这样整个表格就消失,而无法再被用了. 另一种方式是Delete不带w ...

  10. ios 指纹识别解锁

    :添加LocalAuthentication.framework框架 :实现过程 #import "ViewController.h" #import <LocalAuthe ...