您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息