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. ConcurrentDictionary中的 TryRemove

    class A { internal int value; } ConcurrentDictionary<int, A> dic = new ConcurrentDictionary< ...

  2. c# winform 多条件查找 外加网络人才回答

    浮生 Э 2012-11-22  c# winform 多条件查找  20 我现在有2个textbox  一个是用户名,另一个是电话   现在想对这两个进行条件查找datagridview里的数据 s ...

  3. RMAN异机恢复实验---转载

    一.RMAN异机恢复实验 2011年3月23日00:44 1.环境介绍: 主机1: 操作系统 REDHAT5.5 IP地址 172.16.1.120 主机名 sigle 数据库版本 10.2.0.4 ...

  4. B1041 [HAOI2008]圆上的整点 数学

    这个题一开始看着没什么思路,但是一看题解就明白了不少,主要是数学证明,代码很好写. 贴个网址: hzwer 题干: 题目描述 求一个给定的圆(x^+y^=r^),在圆周上有多少个点的坐标是整数. 输入 ...

  5. ul和li里面的list-style

    对ul   list-type  只是设置ul的样式对li    list-type 是对li的综合样式设定  语法是 li-style:list-style-type/list-style-imag ...

  6. bzoj1588: [HNOI2002]营业额统计(权值线段树)

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 16863  Solved: 6789[Submit][Sta ...

  7. 数据库操作通用函数,增强可重复利用性能C#,asp.net.sql2005

    using System;using System.Data;using System.Data.SqlClient; namespace com.hua..li{ /// <summary&g ...

  8. Java中Ajaxa中文乱码问题

    客户端: url='test/queryList?itemName='+itemName; //如果只转一次url=encodeURI(toUrl);   到后台时:乱码    servlet里dec ...

  9. jquery对象与DOM对象的转化(简化版):

    1:DOM对象 var apple = document.getElementById('apple'); 2:jquery对象 var _apple = $('#apple'); 3:DOM对象=& ...

  10. macOS下登录store或者xcode等应用时提示【this action could not be completed】

    sudo mkdir -p /Users/Shared sudo chown root:wheel /Users/Shared sudo chmod -R 1777 /Users/Shared === ...