ACM学习历程——HDU4472 Count(数学递推) (12年成都区域赛)

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 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

这个题目可以这样考虑,对于k个节点的这种树,可以先去掉根节点,于是就是若干个这样的树组合而成。自然,这样就能想到,只要剩下的k-1个结点能构成若干个满足条件的树,k个节点便能构成一个满足条件的树。即,当k-1是某个i的倍数时,k的满足条件的树的个数就要加上i的满足条件的树的个数。当然,初始化所有个数全部是0;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#define N 1000000007

using namespace std;

int ans[1005];
int n;

void qt ()
{
    memset (ans, 0, sizeof (ans));
    ans[1] = 1;
    for (int i = 2; i <= 1000; ++i)
    {
        for (int j = 1; j < i; ++j)
        {
            if ((i-1) % j == 0)
                ans[i] = (ans[i] + ans[j]) % N;
        }
    }
}

int main()
{
    //freopen ("test.txt", "r", stdin);
    qt ();
    int times = 1;
    while (scanf ("%d", &n) != EOF)
    {
        printf ("Case %d: %d\n", times++, ans[n]);
    }
    return 0;
}
时间: 2024-10-11 07:27:04

ACM学习历程——HDU4472 Count(数学递推) (12年成都区域赛)的相关文章

ACM学习历程——HDU4814 Golden Radio Base(数学递推) (12年成都区域赛)

Description Golden ratio base (GRB) is a non-integer positional numeral system that uses the golden ratio (the irrational number (1+√5)/2 ≍ 1.61803399 symbolized by the Greek letter φ) as its base. It is sometimes referred to as base-φ, golden mean b

ACM学习历程—HDU 5446 Unknown Treasure(数论)(2015长春网赛1010题)

Problem Description On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere deep in the cave, she found a treasure chest with a com

ACM学习历程—HDU 5025 Saving Tang Monk(广州赛区网赛)(bfs)

Problem Description <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty. In this novel, Monkey King Sun Wukong, pig Zhu Bajie and Sha Wujin

ACM学习历程——HDU5017 Ellipsoid(模拟退火)(2014西安网赛K题)

---恢复内容开始--- Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distance between the original point (0,0,0) and points on the ellipsoid. The distance between two points (x 1,y 1,z 1) and (x 2,y 2,z 2) is defined as  Input

ACM学习历程—UESTC 1226 Huatuo&#39;s Medicine(数学)(2015CCPC L)

题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目就是构造一个对称的串,除了中间的那个只有1个,其余的两边都是对称的两个,自然答案就是2*n-1. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #

HDU2047 阿牛的EOF牛肉串 【数学递推】

阿牛的EOF牛肉串 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19521    Accepted Submission(s): 9125 Problem Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深

uva live 4123 Glenbow Museum 数学递推

// uva live 4123 Glenbow Museum 数学递推 // // 题目大意: // // 对于一个边平行于坐标轴的多边形,我们可以用一个序列来描述,R和O,R表示 // 该顶点的角度为90度,O表示该定点的角度为270.给定序列的长度.问能由这些RO序 // 列组成的星型多边形(内部存在一个点可以看到所有的节点的多边形)的方法数有多少. // // 解题思路: // // 顶点数一定是序列的长度.n小于4无法组成多边形.n为奇数的时候也不行.设R的个数有 // x个,O的个数

ACM学习历程—HDU 4726 Kia&#39;s Calculation( 贪心&amp;&amp;计数排序)

DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so careless and alway forget to carry a number when the sum of two digits exceeds 9. For example, when she calculates 4567+5789, she will get 9246, and for 12

ACM学习历程—HDU 5023 A Corrupt Mayor&#39;s Performance Art(广州赛区网赛)(线段树)

Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this seemed a safe way for mayor X to make money. Becaus