hdu 4472 Count (递推)「建议收藏」

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




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.



hdu 4472 Count (递推)「建议收藏」


The result might be very large, so you should take module operation with modules 10
9 +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;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116626.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux 网卡重启_linux查看网卡是否up

    linux 网卡重启_linux查看网卡是否uplinux重启网卡命令有:1、命令【servicenetworkrestart】;2、命令【ifconfigeth0down/ifconfigeth0up】;3、命令【ifdowneth0/ifupeth0】。本教程操作环境:linux7.3系统,DELLG3电脑。linux重启网卡命令有:一、servicenetworkrestart1、首先用CRT工具连接到Lin…

    2022年9月22日
    0
  • springboot+idea热部署(自动刷新)

    springboot+idea热部署(自动刷新)近来在使用idea做springboot的项目,但是发现每次修改之后我都需要重新将项目关闭再开启,这样比较繁琐,发现通过热部署的方式让我们可以一边修改我们的项目,然后在页面中直接通过刷新展示出来spring为开发者提供了一个名为spring-boot-devtools的模块来使SpringBoot应用支持热部署,提高开发者的开发效率,无需手动重启SpringBoot应用。devtool…

    2022年6月26日
    46
  • mac系统下mysql开机启动总是3307

    mac系统下mysql开机启动总是3307

    2021年9月9日
    52
  • 大数据开发步骤和流程「建议收藏」

    大数据项目开发步骤:第一步:需求:数据的输入和数据的产出;第二步:数据量、处理效率、可靠性、可维护性、简洁性;第三步:数据建模;第四步:架构设计:数据怎么进来,输出怎么展示,最最重要的是处理流出数据的架构;第五步:再次思考大数据系统和企业IT系统的交互;第六步:最终确定选择、规范等;第七步:基于数据建模写基础服务代码;第八步:正式编写第一个模块;第九步:实现其它…

    2022年4月8日
    77
  • 决策树的原理_决策树特征选择

    决策树的原理_决策树特征选择决策树的原理:根据树结构进行决策,可以用于分类和回归。一颗决策树包括一个根结点、若干个内部节点和若干个叶节点。从根节点出发,对每个特征划分数据集并计算信息增益(或者增益率,基尼系数),选择信息增益最大的特征作为划分特征,依次递归,直至特征划分时信息增益很小或无特征可划分,形成决策树。决策树优点1.计算复杂度不高;2.输出结果易于理解;3.不需要数据预处理;4…

    2022年9月3日
    2
  • beanutils.copyproperties原理_beanutils工具类

    beanutils.copyproperties原理_beanutils工具类常用的BeanUtils.copyProperties方法,你知道它的实现原理吗?

    2022年10月3日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号