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
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
对于每一个合法图形。记最底层个数为j,则再添加一层添加的个数必须是j的倍数。能够用dp[i][j]表示i个点最底层为j个时的个数,对于数据范围内的N遍历得到答案。(属于“我为人人”型的递推关系)
dp[i][j]-->dp[i+j*k][j*k](k=1...N)
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define N 1010
#define LL __int64
const int mod=1000000007;
int f[N][N],ans[N];
void inti()
{
int i,j,k;
memset(f,0,sizeof(f));
f[1][1]=1;
for(i=1;i<=1000;i++)
{
for(j=1;j<=1000;j++)
{
if(f[i][j]==0) //由当前合法状态推得其它状态
continue;
for(k=1;k<=1000;k++)
{
int t1=j*k;
int t2=t1+i;
if(t2>1000)
break;
f[t2][t1]+=f[i][j];
if(f[t2][t1]>=mod)
f[t2][t1]%=mod;
}
}
}
for(i=1;i<=1000;i++)
{
int tmp=0;
for(j=1;j<=i;j++)
tmp=(tmp+f[i][j])%mod;
ans[i]=tmp;
}
}
int main()
{
int n,cnt=1;
inti();
while(scanf("%d",&n)!=-1)
{
printf("Case %d: %d\n",cnt++,ans[n]);
}
return 0;
}
hdu 4472 Count (递推)的更多相关文章
- HDU 4747 Mex 递推/线段树
题目链接: acm.hdu.edu.cn/showproblem.php?pid=4747 Mex Time Limit: 15000/5000 MS (Java/Others)Memory Limi ...
- 致初学者(四):HDU 2044~2050 递推专项习题解
所谓递推,是指从已知的初始条件出发,依据某种递推关系,逐次推出所要求的各中间结果及最后结果.其中初始条件或是问题本身已经给定,或是通过对问题的分析与化简后确定.关于递推的知识可以参阅本博客中随笔“递推 ...
- 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& ...
- HDU 2604 Queuing(递推+矩阵)
Queuing [题目链接]Queuing [题目类型]递推+矩阵 &题解: 这题想是早就想出来了,就坑在初始化那块,只把要用的初始化了没有把其他的赋值为0,调了3,4个小时 = = 本题是可 ...
- HDU - 2604 Queuing(递推式+矩阵快速幂)
Queuing Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 1723 DP/递推
题意:有一队人(人数 ≥ 1),开头一个人要将消息传到末尾一个人那里,规定每次最多可以向后传n个人,问共有多少种传达方式. 这道题我刚拿到手没有想过 DP ,我觉得这样传消息其实很像 Fibonacc ...
- hdu 1249 三角形 (递推)
三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- [hdu 2604] Queuing 递推 矩阵快速幂
Problem Description Queues and Priority Queues are data structures which are known to most computer ...
- HDU 5366 dp 递推
The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
随机推荐
- Bigcommerce:安装的出错解决方案
我们在本地安装时报错了,具体如下: 1. The database details you entered are incorrect: You have an error in your SQL s ...
- Swift - 环形进度条(UIActivityIndicatorView)的用法
Swift中,除了条形进度条外,还有环形进度条,效果图如下: 1,环形进度条的基本属性 (1)Style: Large White:比较大的白色环形进度条 White:白色环形进度条 Gray:灰色环 ...
- 纯后端尝试写一个前端slide插件
概述 由于项目组前端人员缺失,又赶上需要在手机端做一个slide效果的页面,所以只能自己硬着头皮上了,写的很简单,请大家不要笑话,只是拿出来分享下,大家先看下完成后的效果,如下: 过程 看了效果图是不 ...
- 用VC制作应用程序启动画面
摘 要:本文提供了四种启动画面制作方法. 使用启动画面一是可以减少等待程序加载过程中的枯燥感(尤其是一些大型程序):二是 可以用来显示软件名称和版权等提示信息.怎样使用VC++制作应用程序的启动画面呢 ...
- C++ 对象的内存布局(上)
C++ 对象的内存布局(上) 陈皓 http://blog.csdn.net/haoel 点击这里查看下篇>>> 前言 07年12月,我写了一篇<C++虚函数表解析>的文 ...
- Java的HashCode
·HashCode就是根据对象存储在内存的地址计算出的一个值.这个值可以标识这个对象的位置.也可以对比两个引用变量是否指向同一个对象. ·String重写了hashCode方法——改为根据字符序列计算 ...
- Swift - 自定义单元格实现微信聊天界面
1,下面是一个放微信聊天界面的消息展示列表,实现的功能有: (1)消息可以是文本消息也可以是图片消息 (2)消息背景为气泡状图片,同时消息气泡可根据内容自适应大小 (3)每条消息旁边有头像,在左边表示 ...
- 苹果手表的真实触感信息(Real Touch Messaging)
苹果手表凭借其炫酷的设计和界面,无疑已成为一个新的科技焦点,也是苹果在可穿戴领域的重头戏. Apple Watch 有一个非常吸引人的特性:Real Touch Messaging,也就是真实触感消息 ...
- Qt 向word中插入文字(使用QAxWidget和QAxObject)
pro 文件中要加入 CONFIG += qaxcontainer 2. main.cpp #include <QApplication> #include <QAxWidget&g ...
- maven的命令使用笔记
(1)创建web项目mvn archetype:create -DgroupId=com.mycompany.webapp -DartifactId=myweb -DarchetypeArtif ...