HDU 4472 Count(数学 递归)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472
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.
For each test case there is a single line containing only one integer n (1 ≤ n ≤ 1000).
Input is terminated by EOF.
1
2
3
40
50
600
700
Case 1: 1
Case 2: 1
Case 3: 2
Case 4: 924
Case 5: 1998
Case 6: 315478277
Case 7: 825219749
题意:
有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(数学 递归)的更多相关文章
- hdu 4472 Count(递推即dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 代码: #include <cstdio> #include <cstring ...
- hdu 4472 Count (递推)
Count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- hdu 4472 Count
递推,一般的dp值: #include<stdio.h> #include<string.h> #define mod 1000000007 ]; int Dp() { a[] ...
- hdu 4472 Count (2012 ACM-ICPC 成都现场赛)
递推,考虑到一n可以由i * j + 1组合出来,即第二层有j个含有i个元素的子树...然后就可以了.. #include<algorithm> #include<iostream& ...
- [dp] hdu 4472 Count
意甲冠军: 鉴于n节点,满足子节点的相同的树节点号的同一层较少不同的形式. 思考: dp[i][j] 代表i节点.最后,一个层j方法节点 由于满足同层节点,所以j一层又一层必须是j 整数倍 所以就能得 ...
- HDU 4472 Count DP题
解题报告:题目大意,给你n个球,要将这n个球从下到上按层次排列,要求同一个层次的的每一个分支的数量都必须相等,问有多少种排列的方法. 此题的一个DP题,假设现在有n个球,要将这n个球排列好,我们就必须 ...
- HDU 4472 Count (DP)
题目:问n个节点构成完全对称的树有多少种方法. 因为树是完全对称的,所以它的子树也是完全对称的. 对于每个树,拿出一个根节点,枚举剩下的节点能拆分成多少个子树. #include <cstdio ...
- HDU 4588 Count The Carries 数学
Count The CarriesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- HDU 4588 Count The Carries (数学,计数)
题意:给定两个十进制数,求二进制中,从x加到y的二进制进了多少位. 析:把这些数字的二进制纵向罗列出来,然后一位一位的把和加起来,最终得到总的进位数.从1到x,第i位上1的总数是x左移i+1位再右移i ...
随机推荐
- SVG.js 元素操作整理(二)-Transform
一.transform()获取或设置矩阵变换 var draw = SVG('svg1').size(300, 300); //Transforming SVG元素矩阵变换 var rect = dr ...
- How to fix Error: listen EADDRINUSE while using nodejs
If I run a server with the port 80, and I try to use xmlHTTPrequest i get this error: Error: listen ...
- 如何设置浏览器禁止使用UC浏览器
通过UA可以判断浏览器是否是UC浏览器 if(navigator.userAgent.indexOf('UCBrowser')>-1) { alert("当前浏览器不支持本站,建议更 ...
- springmvc学习笔记(13)-springmvc注解开发之集合类型參数绑定
springmvc学习笔记(13)-springmvc注解开发之集合类型參数绑定 标签: springmvc springmvc学习笔记13-springmvc注解开发之集合类型參数绑定 数组绑定 需 ...
- js中各种跨域问题实战小结
什么是跨域?为什么要实现跨域呢? 这是因为JavaScript出于安全方面的考虑,不允许跨域调用其他页面的对象.也就是说只能访问同一个域中的资源.我觉得这就有必要了解下javascript中的同源 ...
- oracle的!=与<>
效果是完全一样的 Oracle中有三个不等符号的,分别是: != ^= <>
- 【转】以太网帧、IP报文格式
原文:https://www.cnblogs.com/yongren1zu/p/6274460.html https://blog.csdn.net/gufachongyang02/article/d ...
- Java:双向链表反转实现
有个小需求要求实现一个双向链表的反转于是就有了下边代码: 链表元素结构定义: package com.util; public class LinkedNode<T>{ private T ...
- Python编程工具pycharm的使用
简介 俗话说工欲善其事必先利其器,所以对于程序员来说,使用python编程必须有一个强大的Python编程工具,这款工具就是pycharm. PyCharm是一种Python IDE,带有一整套可以帮 ...
- 【BLE】CC2541之加入自己定义任务
本篇博文最后改动时间:2017年01月06日,11:06. 一.简单介绍 本文介绍怎样在SimpleBLEPeripheralproject中.加入一个香瓜任务. (香瓜任务与project原有任务相 ...