zoukankan      html  css  js  c++  java
  • FZU 2037 Maximum Value Problem

    思路:数学题!
    容易推出结果f[n]=n*f[n-1]+(n-1)!.也即是第一类斯特灵数。

    代码如下:

     1 #include<iostream>
     2 #include<cmath>
     3 #include<cstring>
     4 #include<string>
     5 #include<algorithm>
     6 #include<iomanip>
     7 #include<cstdio>
     8 #define ll long long
     9 #define M 1000001
    10 #define mod 1000000007
    11 using namespace std;
    12 ll an[M];
    13 double p[M];
    14 void init()
    15 {
    16     an[0]=0;an[1]=1;
    17     p[0]=0;p[1]=1;
    18     ll t=1;
    19     for(int i=2;i<M;i++){
    20         an[i]=(i*an[i-1]%mod+t)%mod;
    21         t=(t*i)%mod;
    22         p[i]=p[i-1]+1.0/(double)i;
    23     }
    24 }
    25 int main()
    26 {
    27     int t,n,ca=0;
    28     init();
    29     scanf("%d",&t);
    30     while(t--){
    31         scanf("%d",&n);
    32         printf("Case %d: %I64d %.6lf
    ",++ca,an[n],p[n]);
    33     }
    34     return 0;
    35 }
    View Code
  • 相关阅读:
    pku2351 Colored Sticks
    JSOI2010 满汉全席
    享元模式
    适配器模式
    合成模式
    原型模式
    创建型设计模式
    建造者模式
    装饰模式
    单例模式
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3353696.html
Copyright © 2011-2022 走看看