CodeForces 9 D.How many trees?(dp)
来源:互联网 发布:php socket可以做什么 编辑:程序博客网 时间:2024/05/17 00:17
Description
求
Input
两个整数
Output
输出
Sample Input
3 2
Sample Output
5
Solution
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef unsigned long long ull;typedef long long ll;typedef pair<int,int>P;const int maxn=40;bool flag[maxn][maxn];ull dp[maxn][maxn];ull Solve(int n,int h){ if(flag[n][h])return dp[n][h]; flag[n][h]=1; if(n==h) { if(n==0)return dp[n][h]=1; return dp[n][h]=1ull<<(n-1); } if(((1ll<<h)-1<n)||n<h)return dp[n][h]=0; ull ans=0; for(int h1=0;h1<h;h1++) for(int h2=0;h2<h;h2++) if(max(h1,h2)==h-1) for(int x=0;x<n;x++) ans+=Solve(x,h1)*Solve(n-1-x,h2); return dp[n][h]=ans;}int main(){ int n,h; while(~scanf("%d%d",&n,&h)) { ull ans=0; for(int i=h;i<=n;i++)ans+=Solve(n,i); printf("%I64u\n",ans); } return 0;}
阅读全文
0 0
- CodeForces 9 D.How many trees?(dp)
- codeforces 9D How many trees?(DP,注意状态表示方法)
- CodeForces 9D How many trees?
- Codeforces 9D How many trees? 题解
- Codeforces Beta Round #9 (Div. 2 Only), problem: (D) How many trees? DP
- Codeforces Beta Round #9 (Div. 2 Only) D. How many trees? dp
- codeforces 9D How many trees? (组合二叉树)
- #9 (Div. 2 Only) D. How many trees? (dp)(好题)
- hdu 1130 How Many Trees? (java)
- UVa10303 - How Many Trees?
- Codeforces_9D-How many trees?
- How Many Trees?
- hdu1130-How Many Trees?
- How Many Trees?
- How Many Trees?
- How Many Trees?
- HDU How Many Trees?
- codeforces #331 D. Wilbur and Trees (dp)
- 19. Remove Nth Node From End of List
- 面试纪录
- Sublime Text 工具使用
- android开发笔记之高德地图使用
- 我的姥爷走了,今后再也没有这个严厉而又较真儿的人
- CodeForces 9 D.How many trees?(dp)
- [duyi]171222 DOM
- (三)java数据库篇笔记库(35)
- java设计模式(二)---抽象工厂模式
- 控制字体样式+弹性盒子模型[后面](个人认为rgba比较重要:因为在做hover的效果时用的比较多还有弹性盒子模型,做导航栏很方便的)
- 烦人的幻灯片
- 数组中的最长连续序列
- Maximum Subarray
- WPF下Window设置WindowStyle="None"时实现鼠标拖动移动窗口位置