zoukankan      html  css  js  c++  java
  • Dream_Chaser队训练赛第一场 I题

    Dream_Chaser队训练赛第一场 I题

    题目来自2012成都区域赛

    I - Count
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    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
     
    思路:递推式类似fib数列,加记忆化或者递推即可。
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<vector>
     7 #include<stack>
     8 #include<queue>
     9 #include<map>
    10 #include<set>
    11 #include<math.h>
    12 #include<string>
    13 #include<cctype>
    14 
    15 using namespace std;
    16 
    17 const int maxn=1000100;
    18 const int INF=(1<<29);
    19 const double EPS=0.00000001;
    20 typedef long long ll;
    21 const ll p=1000000000+7;
    22 
    23 ll n;
    24 ll F[maxn];
    25 
    26 ll f(ll n)
    27 {
    28     if(F[n]!=-1) return F[n];
    29     if(n==1) return F[n]=1;
    30     if(n==2) return F[n]=1;
    31     if(n==3) return F[n]=2;
    32     //return f(n-1)+(n%2==1?1:0)+1;
    33     ll res=0;
    34     res=(res%p+f(n-1)%p+1)%p;
    35     for(int i=2;i<=n/2;i++){
    36         if(n%i==1) res=(res%p+f(n/i)%p)%p;
    37     }
    38     return F[n]=res%p;
    39 }
    40 
    41 void play()
    42 {
    43     for(int i=1;i<=1010;i++){
    44         printf("%I64d,",f(i));
    45         if(i%7==0) printf("
    ");
    46     }
    47 }
    48 
    49 int main()
    50 {
    51     memset(F,-1,sizeof(F));
    52     int tag=1;
    53     while(cin>>n){
    54         printf("Case %d: %I64d
    ",tag++,f(n));
    55     }
    56     return 0;
    57 }
    View Code
     
     
    没有AC不了的题,只有不努力的ACMER!
  • 相关阅读:
    Red Black Tree 红黑树 AVL trees 2-3 trees 2-3-4 trees B-trees Red-black trees Balanced search tree 平衡搜索树
    Red Black Tree java.util.TreeSet
    finding friends with mapreduce
    zabbix 监控jmx 需要--enable-java
    zabbix 监控jmx 需要--enable-java
    zabbix 监控jvm
    zabbix 监控jvm
    eval 捕获dbi错误
    eval 捕获dbi错误
    eval 捕获错误
  • 原文地址:https://www.cnblogs.com/--560/p/4543047.html
Copyright © 2011-2022 走看看