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

对于每一个合法图形。记最底层个数为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 (递推)的更多相关文章

  1. HDU 4747 Mex 递推/线段树

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=4747 Mex Time Limit: 15000/5000 MS (Java/Others)Memory Limi ...

  2. 致初学者(四):HDU 2044~2050 递推专项习题解

    所谓递推,是指从已知的初始条件出发,依据某种递推关系,逐次推出所要求的各中间结果及最后结果.其中初始条件或是问题本身已经给定,或是通过对问题的分析与化简后确定.关于递推的知识可以参阅本博客中随笔“递推 ...

  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. HDU 2604 Queuing(递推+矩阵)

    Queuing [题目链接]Queuing [题目类型]递推+矩阵 &题解: 这题想是早就想出来了,就坑在初始化那块,只把要用的初始化了没有把其他的赋值为0,调了3,4个小时 = = 本题是可 ...

  6. HDU - 2604 Queuing(递推式+矩阵快速幂)

    Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. hdu 1723 DP/递推

    题意:有一队人(人数 ≥ 1),开头一个人要将消息传到末尾一个人那里,规定每次最多可以向后传n个人,问共有多少种传达方式. 这道题我刚拿到手没有想过 DP ,我觉得这样传消息其实很像 Fibonacc ...

  8. hdu 1249 三角形 (递推)

    三角形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  9. [hdu 2604] Queuing 递推 矩阵快速幂

    Problem Description Queues and Priority Queues are data structures which are known to most computer ...

  10. HDU 5366 dp 递推

    The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...

随机推荐

  1. Element.Event

    addEvent(type,fn):为DOM元素增加一个事件监听器 removeEvent(type,fn):移除先前为DOM元素添加的事件监听器 eg: var destroy = function ...

  2. hadoop深入研究:(五)——Archives

    转载请注明来源地址:http://blog.csdn.net/lastsweetop/article/details/9123155 简介 我们在hadoop深入研究:(一)——hdfs介绍里已讲过, ...

  3. HDU4712-----Hamming Distance------超级大水题

    本文出自:http://blog.csdn.net/dr5459 题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4712 题目意思: 海明距离:任意两个 ...

  4. ABP分层设计

    ABP分层设计 一.为什么要分层 分层架构是所有架构的鼻祖,分层的作用就是隔离,不过,我们有时候有个误解,就是把层和程序集对应起来,就比如简单三层架构中,在你的解决方案中,一般会有三个程序集项目:XX ...

  5. 注解框架---AndroidAnnotations

    AndroidAnnotations是一个开源框架,旨在加快Android开发的效率.通过使用它开放出来的注解api,你差点儿可以使用在不论什么地方, 大大的降低了无关痛痒的代码量,让开发人员可以抽身 ...

  6. 名字修饰约定extern "C"与extern "C++"浅析

    所谓名字修饰约定,就是指变量名.函数名等经过编译后重新输出名称的规则. 比如源代码中函数名称为int Func(int a,int b),经过编译后名称可能为?Func@@YAHHH@Z.?Func@ ...

  7. 02将代码开源到github(不会使用github的来看看吧)

    github不多说了,新建一个repository.如图: 这个创建好了之后,我们在eclipse中新建项目WeatherPro,安装githubclient. 安装好了之后,打开git bash,进 ...

  8. THashMD5,THashSHA1,THashBobJenkins,TIdHashMessageDigest5的用法

    [delphi] view plain copy unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils ...

  9. [Android学习笔记]startActivityForResult和onActivityResult的使用

    发开过程中,免不了多个页面之间相互交互通信. Android中使用startActivityForResult方法和onActivityResult配合完成任务 startActivityForRes ...

  10. A Game of Thrones(16) - Edard

    “They’ve found her, my lord.” Ned rose quickly. “Our men or Lannister’s?” “It was Jory,” his steward ...