您的位置:首页 > 产品设计 > UI/UE

fzu 2037 Maximum Value Problem

2015-03-30 11:11 288 查看
http://acm.fzu.edu.cn/problem.php?pid=2037

思路:找规律,找出递推公式f
=f[n-1]*n+(n-1)!,另一个的结果也是一个递推,s
=s[n-1]+1/n;

#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1000010
#define ll long long
using namespace std;
const int mod=1000000007;

ll f[maxn];
int t;
ll n;
ll h[maxn];
double ans[maxn];

void inti()
{
h[0]=1;
h[1]=1;
ans[1]=1.0;
for(int i=2; i<=maxn; i++)
{
ans[i]=ans[i-1]+1.0/i;
h[i]=h[i-1]*i;
h[i]%=mod;
}
f[1]=1;
for(int i=2; i<=maxn; i++)
{
f[i]=(f[i-1]*i+h[i-1])%mod;
}
}

int main()
{
inti();
scanf("%d",&t);
for(int cas=1; cas<=t; cas++)
{
scanf("%lld",&n);
printf("Case %d: %I64d %.6lf\n",cas,f
,ans
);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: