hdu 4472 Count 动态规划
来源:互联网 发布:h3c acl 配置端口访问 编辑:程序博客网 时间:2024/06/05 04:09
Count
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2141 Accepted Submission(s): 1416
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.
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.
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
1234050600700
Sample Output
Case 1: 1Case 2: 1Case 3: 2Case 4: 924Case 5: 1998Case 6: 315478277Case 7: 825219749
Source
2012 Asia Chengdu Regional Contest
Recommend
liuyiding | We have carefully selected several similar problems for you: 5508 5507 5506 5505 5504
解题报告:
每组测试给出一个n,求满足下列要求的树的个数,mod 1e9+7:
1.结点总数为n
2.有且仅有一个树根
3.相同深度的结点 其子结点个数相等
动归解决问题,逐步递推求解
dp[i][j]表示i个结点时,并且要求最底下一层是j个结点时 答案。
ans[i]=dp[i][1]+dp[i][2]+...+dp[i][i-1];
for(int i=2;i<=N;i++)
{
for(int j=1;j<i;j++)
{
int num=i-j;
for(int k=0;k<ve[num].size();k++) //遍历num的约数
{
int x=ve[num][k];
dp[i][num]=(dp[i][num]+dp[j][x])%mod;
}
}
}
整个递推的难点就是逐层递推。
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<climits>#include<queue>#include<vector>#include<map>#include<sstream>#include<set>#include<stack>#include<cctype>#include<utility>#pragma comment(linker, "/STACK:102400000,102400000")#define PI 3.1415926535897932384626#define eps 1e-10#define sqr(x) ((x)*(x))#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)#define lson num<<1,le,mid#define rson num<<1|1,mid+1,ri#define MID int mid=(le+ri)>>1#define zero(x)((x>0? x:-x)<1e-15)#define mk make_pair#define _f first#define _s secondusing namespace std;//const int INF= ;typedef long long ll;//const ll inf =1000000000000000;//1e15;//ifstream fin("input.txt");//ofstream fout("output.txt");//fin.close();//fout.close();//freopen("a.in","r",stdin);//freopen("a.out","w",stdout);const int INF =0x3f3f3f3f;const int maxn= 1010 ;//const int maxm= ;const int N=1000;const ll mod=1e9+7;ll ans[maxn];ll dp[maxn][maxn];vector<int >ve[maxn];void pre()//存储约数{ for(int i=1;i<=N;i++) ve[i].clear(); for(int i=1;i<=N;i++) { for(int j=1;j<=i;j++) { if(i%j==0) ve[i].push_back(j); } }}void work(){ memset(dp,0,sizeof dp); dp[1][1]=1; for(int i=2;i<=N;i++) { for(int j=1;j<i;j++) { int num=i-j; for(int k=0;k<ve[num].size();k++) //遍历num的约数 { int x=ve[num][k]; dp[i][num]=(dp[i][num]+dp[j][x])%mod; } } }}void Getans(){ memset(ans,0,sizeof ans); for(int i=2;i<=N;i++) { ll & x=ans[i]; for(int j=1;j<=i-1;j++) { x=(x+dp[i][j])%mod; } } ans[1]=1;}int main(){ pre(); work(); Getans(); int x,kase=0; while(~scanf("%d",&x)) { printf("Case %d: %lld\n",++kase,ans[x]); } return 0;}
for(int i=2;i<=N;i++)
{
for(int j=1;j<i;j++)
{
int num=i-j;
for(int k=0;k<ve[num].size();k++) //遍历num的约数
{
int x=ve[num][k];
dp[i][num]=(dp[i][num]+dp[j][x])%mod;
}
}
}
{
for(int j=1;j<i;j++)
{
int num=i-j;
for(int k=0;k<ve[num].size();k++) //遍历num的约数
{
int x=ve[num][k];
dp[i][num]=(dp[i][num]+dp[j][x])%mod;
}
}
}
0 0
- hdu 4472 Count 动态规划
- |Hdu 3336|KMP|动态规划|Count the string
- Count the string 动态规划
- HDU1223 Order Count 动态规划 组合数
- 动态规划-hdu 2955
- hdu 动态规划
- HDU动态规划专题
- HDU 1028 动态规划
- hdu 1078 动态规划
- HDU 2069 动态规划
- HDU 1160 动态规划
- HDU 1158 动态规划
- hdu 1176 动态规划
- hdu 1423 动态规划
- 动态规划 --- hdu 1003 **
- 动态规划 --- hdu 1176 **
- HDU 1421 动态规划
- hdu 3199 动态规划
- MAC下如何解压.bin文件
- uva705 Slash Maze
- 获取iOS设备型号的方法总结
- 《Linux Shell》笔记之sed与正则表达式(实例总结) 未完待续
- IOS自适应前段库-Masonry的使用
- hdu 4472 Count 动态规划
- 物联网核心协议—消息推送技术演进
- 向前(上)兼容与向后(下)兼容的区分
- nodejs Error: Cannot find module 'cookie-session'
- IOS--错误集锦--cell.accessoryType不显示内容
- 约瑟夫环 猴子选大王的问题
- multithreading--创建Thread线程的第二种方式,Runnable
- RxJava 各种操作符(2、3)
- Struts2标签实现for循环