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


相关推荐

  • oracle报错注入方式_停止mysql服务的命令

    oracle报错注入方式_停止mysql服务的命令Oracle报错注入原理通过ctxsys.drithsx.sn(user,查询语句)函数来根据页面报错获取我们需要的内容注意事项:1.oracle数据库在查询时,必须写表名,如果表不存在可以使用虚表dual2.Oracle数据库的字段数据类型是强匹配,必须保持数据类型相同3.Oracle系统表all_tables、user_tables、all_tab_columns、user_tab_columns4.oracle限制查询结果返回的数量用rownum靶场:http://59.63.2

    2022年9月27日
    2
  • CreateMutex详解–转

    CreateMutex详解–转一、介绍原型HANDLECreateMutex(LPSECURITY_ATTRIBUTESlpMutexAttributes,//指向安全属性的指针BOOLbInitialOwner

    2022年7月3日
    21
  • POJ3111 K Best(另类背包+二分+变态精度)

    POJ3111 K Best(另类背包+二分+变态精度)POJ3111KBest,看讨论区说数据有点变态,精度要求较高,我就直接把循环写成了100次,6100ms过,(试了一下30,40都会wa,50是4000ms)  第一次在POJ上看到下面这种东西还是很好奇的,  一个题目可以接受多种正确答案,即有多组解的时候,题目就必须被SpecialJudge.SpecialJudge程序使用输入数据和一些其他信息来判答你程序的输出,并将…

    2022年7月27日
    11
  • AndroidO(8.0) 和 Android P(9.0)

    大早上躺床上就索性百度了下p和o发现百度百科的说明还是很简洁易懂的2017年8月22日,谷歌正式发布了Android8.0的正式版,其正式名称为:AndroidOreo(奥利奥) 。奥利奥版安卓的聚焦重点是电池续航能力、速度和安全,让用户更好地控制各种应用程序,加大了对App在后台操作的限制。这种限制在一定程度上延长了安卓机在“睡眠”(Doze)模式下的电池的续航能力,它让不在使用的App进…

    2022年4月7日
    42
  • 打印纸张尺寸换算_常用纸张尺寸大小对照表

    打印纸张尺寸换算_常用纸张尺寸大小对照表648A3297×420B3353×500C3324×458A4210×297B4250×353C4229×324A5148×210B5176×250C5162×229A6105×148B6125×176C6114×162A774×105B788×125C781×114A852×74B862×88DL110×220A937×52B944×62C7/681×162A1026×37B1031×44A组…

    2022年6月20日
    60
  • pytest fixtures_today fixture

    pytest fixtures_today fixturefixture的优势Pytest的fixture相对于传统的xUnit的setup/teardown函数做了显著的改进:命名方式灵活,不局限于setup和teardown这几个命名conf

    2022年8月6日
    4

发表回复

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

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