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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 数据库删除语句[通俗易懂]

    数据库删除语句[通俗易懂]Delete:删除数据表中的行(可以删除某一行,也可以在不删除数据表的情况下删除所有行)。删除某一行:Deletefrom数据表名称where列名称=值;删除所有行:Delete*from数据表名称Drop:删除数据表或数据库,或删除数据表字段。删除数据库:dropdatabase数据库名称删除数据表:(表的结构、属性、索引也会被删除)

    2022年10月22日
  • ROC曲线的通俗理解

    ROC曲线的通俗理解在准备机器学习导论课程考试的过程中,发现自己根据西瓜书上的讲解总是也理解不上去ROC曲线的含义。于是在网络上寻求答案,发现一篇讲解得不错的博客【1】,说得比西瓜书好很多,通俗易懂。这里说一下自己的感想和理解对于已经有数据标签的训练样本,可以得到它们的评分: 其中class一栏表示真实值,p为正例,n为反例,这20个样本中有10个正例10个反例;score一栏则是分类器给出的分类评分。一…

    2022年5月16日
  • linux一些常用命令_运行命令

    linux一些常用命令_运行命令Linux常用命令大全第一章Linux基础命令【1】linux-》ls【2】linux-》alias【3】linux-》cd【4】linux-》clear【5】linux-》date【6】linux-》dpkg【7】linux-》echo【8】linux-》man手册【9】linux-》pwd【10】linux-》sort【11】linux-》uniq【12】linux-》which【13】linux-》管道|第二章Linux文件管理命令【14】linux-》cat

    2022年9月16日
  • C++虚析构函数和纯虚析构函数

    C++虚析构函数和纯虚析构函数1、为什么要使用虚析构函数我们知道析构函数是在对象生命周期结束时自动被调用,用来做一些清理工作(如释放句柄,释放堆内存等),防止出现内存泄漏。那怎么还有虚析构函数呢?使用虚析构函数的类一般是要作为基类,被其他类继承。通过把基类的析构函数声明为虚函数,就可以通过父类指针来释放子类对象,从而完成子类的一些清理工作,防止出现内存泄漏。案例1:基类析构函数为非虚函数//test.hclassParent{public:Parent();~Parent

    2022年6月17日
  • 如何配置android的adb环境变量(jre环境变量配置)

    一、安装完AndroidStudio后会默认在其下面安装SDK1.找到文件sdk下的tools和platform-tools,并复制其路径2.打开环境变量配置3.新建系统变量,命名为Android_ADB,并将上述两个路径分别导入,中间用;隔开4.打开path变量,输入%Android_ADB%5.打开终端,输入adbversion,出现帮助信息,完成配置。二

    2022年4月9日
  • 7-1 判断回文字符串

    7-1 判断回文字符串7-1判断回文字符串(15分)输入一个字符串,判断该字符串是否为回文。回文就是字符串中心对称,从左向右读和从右向左读的内容是一样的。输入格式:输入在一行中给出一个不超过80个字符长度的、以回车结束的非空字符串。输出格式:输出在第1行中输出字符串。如果它是回文字符串,在第2行中输出Yes,否则输出No。输入样例1:level输出样例1:levelYes输入样例2:1+2=2+1=输出样例2:1+2=2+1=No双指针法#include<s

    2022年5月29日

发表回复

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

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