USACO 2.3 Cow Pedigrees (nocows)
来源:互联网 发布:java彩票合买系统搭建 编辑:程序博客网 时间:2024/04/29 08:08
//Main idea: //Dynamic Programming//dp[i][j] denote the number of binary trees whose node number is i and height is less or equal to j;//state transition equation://dp[i][j] = dp[m][j-1]*dp[i-1-m][j-1];//dp[m][j-1] denote the left subtree with m nodes and no more than j-1 height ;//and dp[i-1-m][j-1] denote the right subtree i-1-m nodes(the root take 1 node and left subtree take m),//no more than j-1 height;//So the number of birnary trees with i nodes and j height is dp[i][j]-dp[i][j-1];/*ID: haolink1PROG: nocowsLANG: C++*///#include <iostream>#include <fstream>using namespace std;int dp[200][100];int main(){ ifstream fin("nocows.in"); int node_num, hight; fin >> node_num >> hight; //boundary conditions for(int j = 1; j <= hight; j++){ dp[1][j] = 1; } for(int i = 2; i <= node_num; i++){ for(int j = 2; j <= hight; j++){ for(int m = 1; m <= i-2; m++){ //mod dp[i][j] by 9901 in case it exceed the int max positive value and become negative; dp[i][j] = (dp[i][j] + dp[m][j-1]*dp[i-1-m][j-1])%9901; } } } ofstream fout("nocows.out"); //Note: after mod operation, dp[node_num][hight] may be less than dp[node_num][hight-1]; //So we add 9901 at the end; fout << (dp[node_num][hight] - dp[node_num][hight-1] + 9901)%9901<<endl; return 0;}
0 0
- USACO 2.3 Cow Pedigrees (nocows)
- USACO 2.3Cow Pedigrees
- USACO2.3.2 Cow Pedigrees (nocows)
- USACO2.3.2 Cow Pedigrees (nocows)
- USACO 2.3.2 Cow Pedigrees
- USACO Section 2.3 Cow Pedigrees
- USACO 2.3.2 Cow Pedigrees
- USACO--2.3Cow Pedigrees+DP
- USACO 2.3.2 Cow Pedigrees
- USACO 2.3 Cow Pedigrees 题解
- USACO 2.3 Cow Pedigrees (DP动态规划)
- USACO-Section 2.3 Cow Pedigrees(DP)
- usaco-Cow Pedigrees
- [usaco] Cow Pedigrees
- usaco:Cow Pedigrees
- usaco Cow Pedigrees
- USACO: Cow Pedigrees dp
- USACO-Cow Pedigrees
- Centos虚拟机克隆后,网卡地址冲突问题解决
- Week4 Assignment - Without Full Score - Princeton-Algorithms-PartI
- 自定义控件---动态无限级生成 级联comboBox 和 treeView
- Java 扑克牌发牌
- solr date时间差8小时解决办法
- USACO 2.3 Cow Pedigrees (nocows)
- LINUX 内核源文件介绍以及头文件介绍
- 数组模版类(有错误)
- 在Windows8系统中进行JAVA环境变量的配置
- eclipse 中快捷键
- USACO 2.3 Zero Sum (zerosum)
- php生成静态类html文件
- JAVA ACM 基础
- 营销工具的智慧