Cow Pedigrees

Silviu Ganceanu -- 2003

Farmer John is considering purchasing a new herd of cows. In this new herd, each mother cow gives birth to two children. The relationships among the cows can easily be represented by one or more binary trees with a total of N (3 <= N < 200) nodes. The trees have these properties:

  • The degree of each node is 0 or 2. The degree is the count of the node's immediate children.
  • The height of the tree is equal to K (1 < K < 100). The height is the number of nodes on the longest path from the root to any leaf; a leaf is a node with no children.

How many different possible pedigree structures are there? A pedigree is different if its tree structure differs from that of another pedigree. Output the remainder when the total number of different possible pedigrees is divided by 9901.

PROGRAM NAME: nocows

INPUT FORMAT

  • Line 1: Two space-separated integers, N and K.

SAMPLE INPUT (file nocows.in)

5 3

OUTPUT FORMAT

  • Line 1: One single integer number representing the number of possible pedigrees MODULO 9901.

SAMPLE OUTPUT (file nocows.out)

2

OUTPUT DETAILS

Two possible pedigrees have 5 nodes and height equal to 3:

           @                   @
/ \ / \
@ @ and @ @
/ \ / \
@ @ @ @ ————————————————————————题解
其实一眼就是dp啊……但是我dp弱成渣了
哎呀自己辣么久都没有刷USACO了呢……趁着国庆赶紧第二章结业吧……
其实一开始都没有想出来怎么搞,然后看别人题解说从下往上搞
好机智啊这样真的……然后就会了……
首先呢我们转移时相当于在两个子树上加一个根节点,但是相同高度节点数相同的子树再合并的话就一次
如果高度不同的话就两次,因为位置可以交换
枚举高度要花m个时间,然后就会T,所以我们记录个前缀和然后就可以秒过了
 /*
ID: ivorysi
PROG: nocows
LANG: C++
*/ #include <iostream>
#include <string.h>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>
#include <cmath>
#include <queue>
#define ivorysi
#define mo 1000000007
#define siji(i,x,y) for(int i=(x);i<=(y);i++)
#define gongzi(j,x,y) for(int j=(x);j>=(y);j--)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);i++)
#define sigongzi(j,x,y) for(int j=(x);j>(y);j--)
#define ivory(i,x) for(int i=head[x];i;i=edge[i].n)
#define pii pair<int,int>
#define fi first
#define se second
#define inf 0x5f5f5f5f
#define N 5005
typedef long long ll;
using namespace std;
int dp[][];
int g[][];
int n,m;
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("nocows.in","r",stdin);
freopen("nocows.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
dp[][]=;
g[][]=;
siji(i,,m) {
siji(j,,n) {
if(j+>n) break;
siji(k,,n) {
if(j+k+>n) break;
dp[j+k+][i]=(1LL*dp[j+k+][i]+1LL*dp[j][i-]*dp[k][i-])%;
}
} if(i->=) {
siji(j,,n) {
if(j+>n) break;
siji(k,,n) {
if(j+k+>n) break;
dp[j+k+][i]=(1LL*dp[j+k+][i]+1LL*dp[j][i-]*g[k][i-]*)%;
}
}
}
siji(l,,n) g[l][i]=(g[l][i-]+dp[l][i])%;
//一开始这句话的位置放错了,应该这一个高度算完之后再记录,否则会比较小
}
printf("%d\n",dp[n][m]%);
return ;
}

USACO 2.3 Cow Pedigrees的更多相关文章

  1. USACO Section2.3 Cow Pedigrees 解题报告 【icedream61】

    nocows解题报告------------------------------------------------------------------------------------------ ...

  2. 洛谷P1472 奶牛家谱 Cow Pedigrees

    P1472 奶牛家谱 Cow Pedigrees 102通过 193提交 题目提供者该用户不存在 标签USACO 难度普及+/提高 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 农民约翰准备 ...

  3. 【USACO 2.3】Cow Pedigrees(DP)

    问n个结点深度为k且只有度为2或0的二叉树有多少种. dp[i][j]=dp[lk][ln]*dp[rk][j-1-ln],max(lk,rk)=i-1. http://train.usaco.org ...

  4. USACO Section 2.3 奶牛家谱 Cow Pedigrees

    OJ:http://www.luogu.org/problem/show?pid=1472 #include<iostream> using namespace std; const in ...

  5. USACO Cow Pedigrees 【Dp】

    一道经典Dp. 定义dp[i][j] 表示由i个节点,j 层高度的累计方法数 状态转移方程为: 用i个点组成深度最多为j的二叉树的方法树等于组成左子树的方法数 乘于组成右子树的方法数再累计. & ...

  6. [USACO Section 2.3] Cow Pedigrees (动态规划)

    题目链接 Solution 我DP太菜啦... 考虑到一棵二叉树是由根节点以及左儿子和右儿子构成. 所以答案其实就是 左儿子方案数*右儿子方案数 . 状态定义: \(f[i][j]\) 代表深度为 \ ...

  7. USACO 6.1 Cow XOR

    Cow XORAdrian Vladu -- 2005 Farmer John is stuck with another problem while feeding his cows. All of ...

  8. USACO 2012 Feb Cow Coupons

    2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MB Submit: 349 Solved: 181 [Su ...

  9. USACO 2.4 Cow Tours

    Cow Tours Farmer John has a number of pastures on his farm. Cow paths connect some pastures with cer ...

随机推荐

  1. 【微信开发】微信公众平台接入及绑定提示“请求URL超时”的解决办法

    成为微信开发者的第一步--微信公众平台接入 第一步:填写服务器配置 在开发->基本配置处启用服务器配置.修改配置 其中URL是开发者用来接收微信消息和事件的接口URL. Token可由开发者可以 ...

  2. 驱动10.nor flash

    1 比较nor/nand flash NOR                                  NAND接口:    RAM-Like,引脚多                 引脚少, ...

  3. Python中的各种装饰器详解

    Python装饰器,分两部分,一是装饰器本身的定义,一是被装饰器对象的定义. 一.函数式装饰器:装饰器本身是一个函数. 1.装饰函数:被装饰对象是一个函数 [1]装饰器无参数: a.被装饰对象无参数: ...

  4. 2017年IT互联网圈跑会指南~

    啦啦啦~要放假啦,还有十多天就要过年啦,要走亲访友啦!相信大家也是各种胡吃海喝后,啊咧~腰上好像多了好几圈o(>﹏<)o为了让小伙伴们及时制定年后行程(减膘)计划,活动家特此奉上2017年 ...

  5. Linux学习笔记-epoll

    #include <sys/epoll.h> epoll是Linux内核的一个系统调用,一种可扩展的I/O事件通知机制,最早在Linux内核2.5.44版本引入. 它的功能是监视多文件描述 ...

  6. C# winform调用东软动态库的问题

    在C# winform程序中调用东软的动态库ESActiveX.ocx 如果是引用ESActiveX.ocx,然后在代码中设置示例,调用就会报"灾难性错误" 如果在工具箱中点击右键 ...

  7. 9.mybatis动态SQL标签的用法

    mybatis动态SQL标签的用法   动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么 ...

  8. HDU 1272 小希的迷宫(乱搞||并查集)

    小希的迷宫 Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有 ...

  9. Linux下的数据监控工具

    Vmstat Vmstat,virtual memmory statistics(虚拟内存统计),主要是对操作系统的内存信息.进程状态.cpu活动等进行监视,但是它不能对某个进程进行深入的分析. Pr ...

  10. iOS7之后经过滑动返回导航栏隐藏和显示带来的坑(转载)

    iOS7之后经过滑动返回导航栏隐藏和显示带来的坑 Apple 自从iOS7之后增加了屏幕边缘右滑返回交互的支持,再配合UINavigationController的交换动画,pop上一级的操作变的非常 ...