http://acm.fzu.edu.cn/problem.php?pid=2037

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

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1000010
#define ll long long
using namespace std;
const int mod=; ll f[maxn];
int t;
ll n;
ll h[maxn];
double ans[maxn]; void inti()
{
h[]=;
h[]=;
ans[]=1.0;
for(int i=; i<=maxn; i++)
{
ans[i]=ans[i-]+1.0/i;
h[i]=h[i-]*i;
h[i]%=mod;
}
f[]=;
for(int i=; i<=maxn; i++)
{
f[i]=(f[i-]*i+h[i-])%mod;
}
} int main()
{
inti();
scanf("%d",&t);
for(int cas=; cas<=t; cas++)
{
scanf("%lld",&n);
printf("Case %d: %I64d %.6lf\n",cas,f[n],ans[n]);
}
return ;
}

fzu 2037 Maximum Value Problem的更多相关文章

  1. FZU - 2037 -Maximum Value Problem(规律题)

    Let’s start with a very classical problem. Given an array a[1…n] of positive numbers, if the value o ...

  2. maximum subarray problem

    In computer science, the maximum subarray problem is the task of finding the contiguous subarray wit ...

  3. 动态规划法(八)最大子数组问题(maximum subarray problem)

    问题简介   本文将介绍计算机算法中的经典问题--最大子数组问题(maximum subarray problem).所谓的最大子数组问题,指的是:给定一个数组A,寻找A的和最大的非空连续子数组.比如 ...

  4. 回溯法——最大团问题(Maximum Clique Problem, MCP)

    概述: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题.最大团问题又称为最大独立集问题(Maximum Independent ...

  5. 贪心 FZU 2013 A short problem

    题目传送门 /* 题意:取长度不小于m的序列使得和最大 贪心:先来一个前缀和,只要长度不小于m,从m开始,更新起点k最小值和ans最大值 */ #include <cstdio> #inc ...

  6. FZU 2218 Simple String Problem(简单字符串问题)

    Description 题目描述 Recently, you have found your interest in string theory. Here is an interesting que ...

  7. FZU - 2218 Simple String Problem(状压dp)

    Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...

  8. FZU - 2218 Simple String Problem 状压dp

    FZU - 2218Simple String Problem 题目大意:给一个长度为n含有k个不同字母的串,从中挑选出两个连续的子串,要求两个子串中含有不同的字符,问这样的两个子串长度乘积最大是多少 ...

  9. FZU 2215 Simple Polynomial Problem(简单多项式问题)

    Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...

随机推荐

  1. android夸项目调用

    将工程A做成android library project. 设置工程A,右键->Properties->Android,将Is library项选中,然后Apply.设置工程B,右键-& ...

  2. Objective-c中autorelease的释放时机

    如果你使用过MRR,autorelease这个关键字应该是太熟悉了,每次在我们生成一个新的对象返回时,都需要向这个对象发送autorelease消息,目的是为了延时释放创建的对象.那到底是在什么时候, ...

  3. C# 反射的简单用法

    新建两个项目:类库(Model)和控制台应用程序(ReflectTest). 在[Model]中添加一个类[User]: namespace Model { public class User { p ...

  4. js知识

    行为=事件+由该事件触发的动作 常用事件:onXxx onLoad           打开网页事件 onUnLoad       关闭事件 onClick        单击事件 onChange  ...

  5. javaweb 中的乱码问题

    一.post 方式 首先我们看下面一段代码,在该HTML中我们指定的编码为“UTF-8”,如图所示. 在该代码中,我们将表单数据提交给ParamServlet 处理 servlet 会将接收到的数据打 ...

  6. cordova 创建ios项目

    cordova create fmscmsios1023 com.weilian.fmscms fmscms cd fmscms cd fmscmsios1023/ cordova platforms ...

  7. iOS开发——扫描二维码——工具类

    (代码已测试好,空闲时间更新……)

  8. ios开发,地图标注聚集。搜索标注title功能

    最近在做地图功能,要实现的就是地图标注聚集,还有搜索地图 地图标注通常都是大头针.如果地图缩小到一定范围的时候,会显示密密麻麻的大头针.这样会显的难看 所以设计了一定区域范围内的大头针,缩小的时候给聚 ...

  9. 代码:Masonry 第三方框架

    必备宏使用前提: //define this constant if you want to use Masonry without the 'mas_' prefix #define MAS_SHO ...

  10. 初尝 Perl

    本文将阐述以下几方面内容: 1.什么是Perl 2.Perl有什么用 3.Windows 下的Perl环境搭建 4.Perl 版Hello World 5.Perl 语法梗概 6.一些参考资料 什么是 ...