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

ACM学习历程——HDU4472 Count(数学递推) (12年长春区域赛)的更多相关文章

  1. ACM学习历程—HDU5396 Expression(递推 && 计数)

    Problem Description Teacher Mai has n numbers a1,a2,⋯,an and n−1 operators("+", "-&qu ...

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

    Problem Description On the way to the next secret treasure hiding place, the mathematician discovere ...

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

    Problem Description <Journey to the West>(also <Monkey>) is one of the Four Great Classi ...

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

    ---恢复内容开始--- Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distanc ...

  5. 2015年ACM长春区域赛比赛感悟

    距离长春区域赛结束已经4天了,是时候整理一下这次比赛的点点滴滴了. 也是在比赛前一周才得到通知要我参加长春区域赛,当时也是既兴奋又感到有很大的压力,毕竟我的第一场比赛就是区域赛水平,还是很有挑战性的. ...

  6. ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)

    Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...

  7. ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) =  ...

  8. ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)

    Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...

  9. ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)

    Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...

随机推荐

  1. Key-Value键值存储原理初识(NOSQL)

    NO-Sql数据库:Not Only不仅仅是SQL 定义:非关系型数据库:NoSQL用于超大规模数据的存储.(例如谷歌或Facebook每天为他们的用户收集万亿比特的数据).这些类型的数据存储不需要固 ...

  2. Flume-1-7-0用户手册

    介绍 概述 Apache Flume是为有效收集聚合和移动大量来自不同源到中心数据存储而设计的可分布,可靠的,可用的系统. Apache Flume的用途不仅限于日志数据聚合.由于数据源是可定制的,F ...

  3. dede内容页调用点击数

     <script src="{dede:field name='phpurl'/}/count.php?view=yes&aid={dede:field name='id'/} ...

  4. leetCode 84.Largest Rectangle in Histogram (最大矩形直方图) 解题思路和方法

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  5. 【Java】Spring Web MVC注意事项

    本文内容可能是书上没有的,至少是<Java Web整合开发实践>这本书上没有的.这是初学Spring的笔者走过的弯路,谨记以自勉. 这两天学习Spring WebMVC,照着书依葫芦画瓢写 ...

  6. 不同特权级间代码段的跳转{ 门 + 跳转(jmp + call) + 返回(ret) }

    [0]写在前面 0.1)我们讲 CPU的保护机制,它是可靠的多任务运行环境所必须的: 0.2) CPU保护机制:分为段级保护 + 页级保护: 0.2.1)段级保护分为:段限长 limit 检查.段类型 ...

  7. Java 8 default 函数

    我们知道在java8之前 ,一个类实现一个接口需要实现接口所有的方法, 但是这样会导致一个问题,当一个接口有很多的实现类的时候,修改这个接口就变成了一个非常麻烦的事,需要修改这个接口的所有实现类 不过 ...

  8. MongoDB C#驱动:

    MongoDB C#驱动: http://xiaosheng.me/2016/09/15/article24 http://www.cnblogs.com/wuhuacong/p/5098348.ht ...

  9. python书写日志的重要性?

    转自:https://blog.csdn.net/weixin_43063753/article/details/82899395 程序为什么要写日志?#为了能够在程序在运行过程中记录错误,方便维护, ...

  10. ES5中的类与继承

    最近在重新复习TypeScript,看到类这块的时候自然会和ES5中的类写法进行对比加深印象. 发现ES5的类与继承一些细节还是挺多的,时间久了容易忘记,特此记录下. 首先是ES5的类定义,这没什么好 ...