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)
上一篇 2022年1月18日 下午1:00
下一篇 2022年1月18日 下午1:00


相关推荐

  • c++ 常量表达式_c语言所有函数

    c++ 常量表达式_c语言所有函数constexpr修饰函数。普通函数/类成员函数。1.函数必须要有返回值,并且return返回的表达式必须是常量表达式。错误代码如下:#include<iostream>usingnamespacestd;//error不是常量表达式函数constexprvoidfunc1(){ inta=200; cout<<a<<endl;}//error不是常量表达式函数因为a是变量,不是常量constexprint

    2026年4月16日
    4
  • VMware 虚拟机里连不上网的五种解决方案「建议收藏」

    VMware 虚拟机里连不上网的五种解决方案「建议收藏」在VMware虚拟机里的虚拟机系统连接不上网络首先,注意查看适配器选项里的网络连接这两个网络连接是否存在,如果不存在可以重新装一下VM如果存在,连不上网解决办法一:虚拟机设置里,找到“网络适配器”,右边的网络连接选择“NAT模式”,如果不行的话再linux系统。还是不行的话接着看第二种解决方案。解决方法二:可能原因是VMwareNETService…

    2022年6月26日
    621
  • 歌曲的BPM (Beat Per Minute)–每分钟节拍数[通俗易懂]

    歌曲的BPM (Beat Per Minute)–每分钟节拍数[通俗易懂]foobar2000解决舞曲挑选

    2022年8月1日
    8
  • 奠定未来智能家居基础 助力江门打造智慧城市

    奠定未来智能家居基础 助力江门打造智慧城市

    2022年3月4日
    45
  • opengl glPushMatrix()[通俗易懂]

    opengl glPushMatrix()[通俗易懂]OpenGL有三个矩阵堆栈,分别是GL_MODELVIEW(模型视图矩阵堆栈)、GL_PROJECTION(投影矩阵堆栈)、GL_TEXTURE(纹理矩阵堆栈),用法和普通堆栈一样;这里我们只讲模型视图矩阵堆栈,OpenGL提供了相应的接口:glPushMatirx()和glPopMatrix()。这个模型视图矩阵堆栈是干嘛用的呢?我们在三维空间中绘制模型,大部分时候需要对模型进行

    2025年8月3日
    5
  • C++求最大公约数和最小公倍数

    C++求最大公约数和最小公倍数方法一:辗转相除法   用"较大数"除以"较小数",再用"较小数"除以"第一余数",再用“第一余数”除以 “第二余数",   如此反复,直到最后余数是0为止。如果是求两个数的最大公约数,那么最后的除数就是这两个数的最大公约数。#include&lt;stdio.h&gt;#include&lt;stdlib.h&gt;#include&a

    2022年5月13日
    38

发表回复

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

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