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 ;
}

最新文章

  1. C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 更优美的Oracle数据库上的代码生成器
  2. ASP.NET MVC分页组件MvcPager 2.0版发布暨网站全新改版
  3. IOS开发之——自定义导航控制器
  4. oracle 自动添加序号列 排序
  5. UITableViewCell性能优化
  6. 火狐浏览器怎么查看页面加载了那些js文件,那系js文件有作用
  7. Windows系统在本地配置一个apache域名的方法
  8. iview服务不可以被访问解决办法
  9. vue history模式
  10. yum源配置问题
  11. python(62):保留两位小数
  12. android项目安装报错:INSTALL_FAILED_CONFLICTING_PROVIDER
  13. UI的设计,适配器,以及RecyclerView无法加载的解决办法
  14. List元素删除不会导致越界但有问题的写法
  15. 【mongoDB】 分享系列
  16. Qt编写百度离线版人脸识别+比对+活体检测
  17. LG3684 [CERC2016]机棚障碍 Hangar Hurdles
  18. Android NDK开发篇(五):Java与原生代码通信(数据操作)
  19. sql递归查询子级
  20. 前后端分离之让前端开发脱离接口束缚(mock)

热门文章

  1. TF101出现“DMClient已停止”处理办法
  2. [C++设计模式] composite 组合模式
  3. 弹出框中选项卡的运用(easyUI)
  4. hdoj--5619--Jam&#39;s store(最小费用最大流)
  5. jq中append()、prepend()、after()、before()的区别
  6. Python 2:str.title()(使字符串每个单词首字母大写)
  7. Windows 环境下 Docker 使用及配置
  8. ie9长度兼容
  9. 青橙 M4 解锁BootLoader 并刷入recovery ROOT
  10. Java常用设计模式《转》