HDU 4472 Count (线性dp 推公式)

来源:互联网 发布:泳衣 知乎 编辑:程序博客网 时间:2024/05/22 13:34

Count

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1631    Accepted Submission(s): 1028



Problem Description
Prof. Tigris is the head of an archaeological team who is currently in charge of an excavation in a site of ancient relics.
This site contains relics of a village where civilization once flourished. One night, examining a writing record, you find some text meaningful to you. It reads as follows.
“Our village is of glory and harmony. Our relationships are constructed in such a way that everyone except the village headman has exactly one direct boss and nobody will be the boss of himself, the boss of boss of himself, etc. Everyone expect the headman is considered as his boss’s subordinate. We call it relationship configuration. The village headman is at level 0, his subordinates are at level 1, and his subordinates’ subordinates are at level 2, etc. Our relationship configuration is harmonious because all people at same level have the same number of subordinates. Therefore our relationship is …”
The record ends here. Prof. Tigris now wonder how many different harmonious relationship configurations can exist. He only cares about the holistic shape of configuration, so two configurations are considered identical if and only if there’s a bijection of n people that transforms one configuration into another one.
Please see the illustrations below for explanation when n = 2 and n = 4.

The result might be very large, so you should take module operation with modules 109 +7 before print your answer.
 

Input
There are several test cases.
For each test case there is a single line containing only one integer n (1 ≤ n ≤ 1000).
Input is terminated by EOF.
 

Output
For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) and Y is the desired answer.
 

Sample Input
1234050600700
 

Sample Output
Case 1: 1Case 2: 1Case 3: 2Case 4: 924Case 5: 1998Case 6: 315478277Case 7: 825219749
 

Source
2012 Asia Chengdu Regional Contest


题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4472


题目大意 :给n个点构成一棵树,要求每层的每个节点的子节点数目相同


题目分析 :用dp[i]表示节点个数为i的方法数,一个节点作为根的时候剩下的i-1个节点进行均分,分成j份所以当(i-1) % j == 0时 dp[i] += dp[j],
这就是这道题的动规方程。最后注意取模

#include <cstdio>int const MAX = 1e3 + 5;int const MOD = 1e9 + 7;int dp[MAX];int main(){    dp[1] = 1;    for(int i = 1; i <= 1000; i++)        for(int j = 1; j < i; j++)            if((i - 1) % j == 0)                dp[i] += dp[j] % MOD;    int n, ca = 1;    while(scanf("%d", &n) != EOF)        printf("Case %d: %d\n", ca++, dp[n] % MOD);}


0 0
原创粉丝点击