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

题意:

有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)

    题目链接: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. [dp] 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 (DP)

    题目:问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. 用纯JAVA代码来创建视图

    package com.kale.codeview; import android.os.Bundle; import android.support.v7.app.ActionBarActivity ...

  2. Mac下的Docker及Kubernetes(k8s)本地环境搭建与应用部署、管理界面kubernetes-dashboard

    mac安装docker: brew cask install docker 当然也可以直接去官网下载docker的pkg文件安装 mac的docker国内镜像:网易的镜像地址:http://hub-m ...

  3. HTTPS为什么更安全,先看这些 , 网络加密 , 加密解密

    投递人 itwriter 发布于 2017-02-27 21:35 评论(10) 有1957人阅读 原文链接 [收藏] « » HTTPS 是建立在密码学基础之上的一种安全通信协议,严格来说是基于 H ...

  4. 【FTP资源】发现一个ArcGIS相关的FTP。

    用谷歌 在搜索 ArcGISEngineRT的时候,发现了一个站点: ftp://ftp.geobc.gov.bc.ca/pub/outgoing/GeoBC_software_distributio ...

  5. c++流缓冲学习---rdbuf()

    我们使用STL编程的时候有时候会想到把一个流对象指向的内容用另一个流对象来输出,比如想把一个文件的内容输出到显示器上,我们可以用简单的两行代码就可以完成: ifstream infile(" ...

  6. CSS-页面滑屏滚动原理

    现在的网站有的时候为了简洁就是很多的单页滑屏滚动介绍,主要呈现方式有两种,一种是整体的元素一直排列下去,假设有五个需要展示的全屏页面,那么高度是500%,只是展示100%,剩下的可以通过transfo ...

  7. 领扣-120 三角形最小路径和 Triangle MD

    三角形最小路径和 Triangle 数组 动态规划 问题 给定一个三角形,找出自顶向下的最小路径和.每一步只能移动到下一行中相邻的结点上. 例如,给定三角形: [2], [3,4], [6,5,7], ...

  8. SSE,MSE,RMSE,R-square指标讲解

    SSE(和方差.误差平方和):The sum of squares due to errorMSE(均方差.方差):Mean squared errorRMSE(均方根.标准差):Root mean ...

  9. hadoop 2.2搭建常见错误

    http://blog.csdn.net/haidao2009/article/details/14897813 hadoop 2.2 搭建 http://blog.csdn.net/pelick/a ...

  10. Windows远程桌面连接的利器-mRemote

    mRemoteNG是Windows平台下一款开源的支持多标签.多协议的远程连接管理器.平时我们可能安装N多款管理工具,如putty.SecureCRT.xshell.SSHshell.mstsc.ex ...