HDU 4472 Count(数学 递归)

时间:2021-12-03 09:07:36

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

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.

HDU 4472 Count(数学 递归)


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
1
2
3
40
50
600
700
 
Sample Output
Case 1: 1
Case 2: 1
Case 3: 2
Case 4: 924
Case 5: 1998
Case 6: 315478277
Case 7: 825219749
 
Source

题意:

有n个点,使之构成一个树。要求每一层的每一个节点的子节点数要同样。问有多少中构造法!

PS:

对于n个点,先将第一个节点(父节点)去掉。由于父节点仅仅有一个,还剩下
n-1 个点,

由于每一层的每一个节点的子节点数要同样,所以将这
n-1 个节点m等分,每份为(n-1)/m个点,

再递归求解就可以。

代码例如以下:

#include <cstdio>
#include <cstring>
#define mod 1000000007
int dp[1017];
void init()
{
dp[1] = 1;
dp[2] = 1;
dp[3] = 2;
for(int i = 4; i <= 1000; i++)
{
for(int j = 1; j < i; j++)
{
if((i-1)%j == 0)
{
dp[i]+=dp[(i-1)/j];
dp[i] %= mod;
}
}
}
}
int main()
{
int n;
int cas = 0;
init();
while(~scanf("%d",&n))
{
printf("Case %d: %d\n",++cas,dp[n]);
}
return 0;
}

HDU 4472 Count(数学 递归)的更多相关文章

  1. hdu 4472 Count(递推即dp&rpar;

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 代码: #include <cstdio> #include <cstring ...

  2. hdu 4472 Count (递推)

    Count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  3. hdu 4472 Count

    递推,一般的dp值: #include<stdio.h> #include<string.h> #define mod 1000000007 ]; int Dp() { a[] ...

  4. hdu 4472 Count (2012 ACM-ICPC 成都现场赛)

    递推,考虑到一n可以由i * j + 1组合出来,即第二层有j个含有i个元素的子树...然后就可以了.. #include<algorithm> #include<iostream& ...

  5. &lbrack;dp&rsqb; hdu 4472 Count

    意甲冠军: 鉴于n节点,满足子节点的相同的树节点号的同一层较少不同的形式. 思考: dp[i][j] 代表i节点.最后,一个层j方法节点 由于满足同层节点,所以j一层又一层必须是j 整数倍 所以就能得 ...

  6. HDU 4472 Count DP题

    解题报告:题目大意,给你n个球,要将这n个球从下到上按层次排列,要求同一个层次的的每一个分支的数量都必须相等,问有多少种排列的方法. 此题的一个DP题,假设现在有n个球,要将这n个球排列好,我们就必须 ...

  7. HDU 4472 Count &lpar;DP&rpar;

    题目:问n个节点构成完全对称的树有多少种方法. 因为树是完全对称的,所以它的子树也是完全对称的. 对于每个树,拿出一个根节点,枚举剩下的节点能拆分成多少个子树. #include <cstdio ...

  8. HDU 4588 Count The Carries 数学

    Count The CarriesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. HDU 4588 Count The Carries (数学,计数)

    题意:给定两个十进制数,求二进制中,从x加到y的二进制进了多少位. 析:把这些数字的二进制纵向罗列出来,然后一位一位的把和加起来,最终得到总的进位数.从1到x,第i位上1的总数是x左移i+1位再右移i ...

随机推荐

  1. 5分钟部署ELK&plus;filebeat5&period;1&period;1

    标题有点噱头,不过网络环境好的情况下也差不多了^_^   1. 首先保证安装了jdk.   elasticsearch, logstash, kibana,filebeat都可以通过yum安装,这里前 ...

  2. 《利用Python进行数据分析: Python for Data Analysis 》学习随笔

    NoteBook of <Data Analysis with Python> 3.IPython基础 Tab自动补齐 变量名 变量方法 路径 解释 ?解释, ??显示函数源码 ?搜索命名 ...

  3. Plan-9效应:为什么东西不坏就不要去修它

    http://www.aqee.net/the-plan-9-effect-or-why-you-should-not-fix-it-if-it-aint-broken/ Plan-9是一个很棒的.很 ...

  4. Windows Developer Day Review

    北京时间 3 月 8 日凌晨 1 点钟,今年的第一次 Windows Developer Day 正式召开.    因为时间太晚看不了直播,我也是第二天早上在公司看的重播.整个会议过程有很多值得去研究 ...

  5. 洛谷P1169&lbrack;ZJOI2007&rsqb;棋盘制作

    题目 一道悬线法的裸题,悬线法主要是可以处理最大子矩阵的问题. 而这道题就是比较经典的可以用悬线法来处理的题. 而悬线法其实就是把矩阵中对应的每个位置上的元素分别向左向上向右,寻找到不能到达的地方,然 ...

  6. php7 三元运算 精简

    $abc = isset($_GET['name'])?$_GET['name']:'abc'; // 5.+ $abcd = $_GET[

  7. LockSupport的源码实现原理以及应用

    一.为什么使用LockSupport类 如果只是LockSupport在使用起来比Object的wait/notify简单, 那还真没必要专门讲解下LockSupport.最主要的是灵活性. 上边的例 ...

  8. jQuery设置下拉框select 默认选中第一个option

    $("#id option:first").prop("selected", 'selected');

  9. &num;2009&period; 「SCOI2015」小凸玩密室

    神仙题啊.完全想不出 首先看方案.可以从任意一个点开始,在这个点要先走完子树,然后走到父亲,再走兄弟,再走父亲的父亲,父亲的兄弟..一直走到1,1的另外一个子树,结束. 完全不会鸭.jpg 设f[i] ...

  10. B树 B&plus;树 红黑树

    B-Tree(B树) 具体讲解之前,有一点,再次强调下:B-树,即为B树.因为B树的原英文名称为B-tree,而国内很多人喜欢把B-tree译作B-树,其实,这是个非常不好的直译,很容易让人产生误解. ...