标签:
http://acm.fzu.edu.cn/problem.php?pid=2037
思路:找规律,找出递推公式f[n]=f[n-1]*n+(n-1)!,另一个的结果也是一个递推,s[n]=s[n-1]+1/n;
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 1000010 5 #define ll long long 6 using namespace std; 7 const int mod=1000000007; 8 9 ll f[maxn]; 10 int t; 11 ll n; 12 ll h[maxn]; 13 double ans[maxn]; 14 15 void inti() 16 { 17 h[0]=1; 18 h[1]=1; 19 ans[1]=1.0; 20 for(int i=2; i<=maxn; i++) 21 { 22 ans[i]=ans[i-1]+1.0/i; 23 h[i]=h[i-1]*i; 24 h[i]%=mod; 25 } 26 f[1]=1; 27 for(int i=2; i<=maxn; i++) 28 { 29 f[i]=(f[i-1]*i+h[i-1])%mod; 30 } 31 } 32 33 int main() 34 { 35 inti(); 36 scanf("%d",&t); 37 for(int cas=1; cas<=t; cas++) 38 { 39 scanf("%lld",&n); 40 printf("Case %d: %I64d %.6lf\n",cas,f[n],ans[n]); 41 } 42 return 0; 43 }
fzu 2037 Maximum Value Problem
标签:
原文地址:http://www.cnblogs.com/fanminghui/p/4377482.html