USACO 2.3 Cow Pedigrees (DP动态规划)

#include <stdio.h>
#define DEBUG 1
#define TESTCASES 9

int main(){
#if DEBUG
	int testCase;
	for (testCase = 1; testCase <= TESTCASES; testCase++){
		char inputFileName[20] = "inputX.txt";
		inputFileName[5] = '1' +  (testCase - 1);
		freopen(inputFileName, "r", stdin);
		printf("\n#%d\n", testCase);
#endif

	int totalNodes, theHight;
	scanf("%d%d", &totalNodes, &theHight);

	int trees[100][200];
	int hight, nodes;
	for (hight = 0; hight <= theHight; hight++)
		for (nodes = 0; nodes <= totalNodes; nodes++)
			trees[hight][nodes] = 0;

	for (hight = 1; hight <= theHight; hight++)
		for (nodes = 1; nodes <= totalNodes; nodes += 2){
			if (nodes == 1){
				trees[hight][nodes] = 1;
				continue;
			}
			int theNodes;
			for (theNodes = 1; theNodes <= nodes - 2; theNodes += 2)
				trees[hight][nodes] = (trees[hight][nodes] + trees[hight - 1][theNodes] * trees[hight - 1][nodes - 1 - theNodes]) % 9901;	
		}

	printf("%d\n", (trees[theHight][totalNodes] - trees[theHight - 1][totalNodes] + 9901) % 9901);

#if DEBUG
	}
#endif
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值