HDU 4472 Count(数学 递归)

题目链接: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.

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

2012 Asia Chengdu Regional Contest

题意:

有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;
}
时间: 2025-01-08 00:45:07

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

hdu 4472 Count

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 题目大意:给你n个节点,组成一个颗树,要求树的每层的每个节点都有相同的儿子树. 思路:除去根节点,我们把n-1节点分成j组,即是把这棵树看成是一棵对称树,每组中的节点数相同.所以dp[i]=sum(dp[j]),(1<=j<=i-1&&(i-1)%j==0) code: #include<cstdio> #include<iostream> #incl

hdu 4472 Count (递推)

Count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1756    Accepted Submission(s): 1133 Problem Description Prof. Tigris is the head of an archaeological team who is currently in charge of a

[dp] hdu 4472 Count

意甲冠军: 鉴于n节点,满足子节点的相同的树节点号的同一层较少不同的形式. 思考: dp[i][j] 代表i节点.最后,一个层j方法节点 由于满足同层节点,所以j一层又一层必须是j 整数倍 所以就能得到兴许的状态 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #include"queue" #include&

hdu 1705 Count the grid(皮克定理)

题目链接:hdu 1705 Count the grid 题意: 给定一个三角形三点坐标,问三角形内有多少个坐标均为整数的点. 题解: 给定顶点坐标均是整点(或正方形格点)的简单多边形,皮克定理说明了其面积 S 和内部格点数目 n.边上格点数目 s 的关系:S = n +s/2+1 三角形两向量叉积/2=面积. 向量上整数点数为gcd(v.x,v.y)(此公式对于一条边上的结果不准确,但是三条边加在一起的和是准确的) 1 #include<bits/stdc++.h> 2 #define F(

HDU 4916 Count on the path

题意: 给定一棵树和m个询问  每个询问要求回答不在u和v两节点所形成的路径上的点的最小标号 思路: 一开始以为是LCA-  不过T了好几次-  后来发现不用LCA也可做 考虑每个询问u和v  如果他们的lca不是1  则1一定是答案  不过求lca会T  那么我们只需要在遍历树的时候给节点染色  染的颜色就是1的儿子的颜色  如果x这个点在y的子树中(y是1的儿子)那么他的颜色就是y 染完色后我们考虑答案是如何构成的 如图所示  答案即是  红色  蓝色  绿色的子树中节点的最小值  那么我们

HDU 4588 Count The Carries(找规律,模拟)

题目 大意: 求二进制的a加到b的进位数. 思路: 列出前几个2进制,找规律模拟. #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <stack> #include <vector> using namespace std; int main() { int

hdu 3336 Count the string

Count the stringTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4239    Accepted Submission(s): 1977 Problem Description It is well known that AekdyCoin is good at string problems as well as num

LA3882 约瑟夫数学递归法

首先,约瑟夫环的数学优化方法为: 为了讨论方便,先把问题稍微改变一下,并不影响原意:问题描述:n个人(编号0~(n-1)),从0开始报数,报到(m-1)的退出,剩下的人继续从0开始报数.求胜利者的编号. 我们知道第一个人(编号一定是(m-1)%n) 出列之后,剩下的n-1个人组成了一个新的约瑟夫环(以编号为k=m%n的人开始):    k k+1 k+2 ... n-2, n-1, 0, 1, 2, ... k-2 并且从k开始报0.现在我们把他们的编号做一下转换: k --> 0 k+1 --

hdu 4811 Ball(数学)

题目链接:hdu 4811 Ball 题目大意:有三种颜色的球若干,每次向桌子上放一个球,保证是一条序列,每次放球的得分为当前放入序列的球的前面有多少种不同的颜色a,后面的有多少种不同的颜色b,a+b.问说给定球的数量后,最大得分为多少. 解题思路:因为放球顺序是自己定的,所以我们可以尽量早得构造一个序列,使得后面放入球的得分均保持在峰值.那么求峰值就要根据球的数量来决定.我们叫得分为峰值的求为最高得分球,它们有很多个.对于一种颜色来说:0个,表示不能为在最高得分球的左边和右边,换句话来说,就是