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. uva 657

    很简单的题,就是题意不懂……! 就是判断每个'*'区域内‘X’区域块的个数 WA了好多次,就是太差了: 1.结果排序输出 2.因为是骰子所以不再1-6范围内的数字要舍弃 3.格式要求要空一行…… 4. ...

  2. Xamainr 地图之webview初探

    一 说几点 当下移动开发主要实现方式有传统的Native以及新的混合开发想Rect.js,nodejs这些前段框架,其本质要么是原生控件来实现UI,要么html来实现UI.Xamarin其实也只是取巧 ...

  3. VC,一条会被鼠标移动的直线

    对话框中的小红线可以被移动的 一.类名是 CBinarizationDlg 二.定义两个变量BOOL m_flag;int nPos;在构造函数初始化m_flag = false;nPos=256;三 ...

  4. 怎样使用jsp实现header和footer与网页内容的分离

    好多显示层框架都自带这样的功能JSF,Wicket,页面布局取决于项目使用的显示层框架. 前台即客户端的布局,通常用在无需跳转的页面.比如同样是用户管理页面,增删改查的操作都希望停留在同一个页面.这时 ...

  5. mybatis 的简单使用

    须要用到的包:(这里仅仅是当中一个版本号.其它的百度) mysql-connector-java-5.1.6-bin mybatis-3.2.2 先看项目文件夹: 配置文件mybatisconfig. ...

  6. Android学习-----如何使用sqlite对于后台数据交换,sqlite使用例程入门

     SQLite 这是一个非常流行的嵌入式数据库.它支持 SQL 查询,和只使用很少的内存.Android 在集成实施 SQLite,所以每 Android 应用程序能够使用 SQLite 数据库. ...

  7. OMR数据查询

    查询 1.查询所有的. var query = from p in _Context.Info select p; var query = _Context.Info; 2.单条件查询 等值查 var ...

  8. 【iOS发展-44】通过案例谈iOS重构:合并、格式化输出、宏观变量、使用数组来存储数据字典,而且使用plist最终的知识

    我们今天的情况下是第一个例子,下面的5一来通过切换页上一页下一页: (1)第一步,基本是以非常傻非常直接的方式来创建.这里用到的主要点有: --把对象变量设置为全局变量使得能够在其它方法中调用来设置它 ...

  9. 开源mp3播放器--madplay 编译和移植 简记

    madplay是一款开源的mp3播放器. http://madplay.sourcearchive.com/ 下面简单记录一下madplay的编译与移植到ARM开发板上的过程 一.编译x86版本的ma ...

  10. Android常用开源项目

    Android开源项目第一篇——个性化控件(View)篇   包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Progre ...