USACO 2.3 Cow Pedigrees (DP动态规划)
2015-10-02 11:06
429 查看
#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; }
相关文章推荐
- C++动态规划之最长公子序列实例
- C++动态规划之背包问题解决方法
- C#使用动态规划解决0-1背包问题实例分析
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- LFC1.0.0 版本发布
- 动态规划
- C++ 动态规划
- Android px、dp、sp之间相互转换
- android中像素单位dp、px、pt、sp的比较
- DP(动态规划) 解游轮费用问题
- Android对px和dip进行尺寸转换的方法
- 动态规划的用法——01背包问题
- 动态规划的用法——01背包问题
- 《收集苹果》 动态规划入门
- 《DNA比对》蓝桥杯复赛试题
- 《背包问题》 动态规划
- 关于爬楼梯的动态规划算法
- 动态规划 --- hdu 1003 **
- Android根据分辨率进行单位转换-(dp,sp转像素px)