HDU 4472 Count
2013-04-23 23:00
405 查看
Count
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 383 Accepted Submission(s): 246
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
1 2 3 40 50 600 700
[align=left]Sample Output[/align]
Case 1: 1 Case 2: 1 Case 3: 2 Case 4: 924 Case 5: 1998 Case 6: 315478277 Case 7: 825219749 [code]#include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <stdlib.h> using namespace std; const int mod = 1000000000+7; const int Max = 1002; int num[Max]; int solve( int n ) { if(num != -1) return num ; int ans = 0, i; ans += solve(n - 1); int k = n - 1; for(i = 2; i < n; i ++){ if(k % i == 0) ans += solve( k - k/i * (i - 1) ); } return ans; } int main() { int n; int cas = 1; memset(num, -1, sizeof(num)); num[0] = 0; num[1] = 1; num[2] = 1; for(int i = 3; i < Max; i ++) num[i] = solve(i) % mod; while( scanf("%d", &n) != EOF ){ printf("Case %d: %d\n", cas++, num ); } return 0; }
[/code]
相关文章推荐
- [HDU] 4472 Count 排列组合型Dp
- HDU 4472 Count DP题
- HDU——4472 Count
- hdu 4472 Count (递推)
- hdu 4472 Count 递推
- HDU 4472 Count(数学 递归)
- HDU 4472 Count (线性dp 推公式)
- HDU 4472 count(递推)
- HDU 4472 Count
- [dp] hdu 4472 Count
- HDU-#4472 Count(DP)
- hdu 4472 Count
- [dp] hdu 4472 Count
- hdu 4472 Count (2012 ACM-ICPC 成都现场赛)
- hdu 4472 Count (递推)
- hdu 4472 count
- Hdu 4472 Count 【动态规划】
- HDU 4472 Count (DP)
- HDU 4472 Count(数学题)
- hdu 4472 count