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. iOS之GCDAsyncSocket第三方库的使用

    Socket描述了一个IP.端口对.它简化了程序员的操作,知道对方的IP以及PORT就可以给对方发送消息,再由服务器端来处理发送的这些消息.所以,Socket一定包含了通信的双发,即客户端(Clien ...

  2. java中判断Object对象类型

    记录一下 Object param = params.get(i); if (param instanceof Integer) { int value = ((Integer) param).int ...

  3. JAVA长连接demo

    http://blog.csdn.net/caomiao2006/article/details/38830475 JAVA长连接demo 2014-08-25 23:20 4767人阅读 评论(2) ...

  4. (一)JAVA使用POI操作excel

    1,Poi 简介 Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office格式档案读和写的功能 PO ...

  5. java新手笔记15 多态

    1.Animal类 package com.yfs.javase; public class Animal { public void cry() { System.out.println(" ...

  6. HDU 4627 The Unsolvable Problem(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 题目大意:给定一个整数n(2 <= n <= 109),满足a+b=n并且[a,b] ...

  7. IOS 学习笔记 2015-04-15 手势密码(原)

    // // WPSignPasswordView.h // 网投网 // // Created by wangtouwang on 15/4/9. // Copyright (c) 2015年 wan ...

  8. Js获取fileupload的绝对路径时总是的到C:\fakepath\+文件名称的 解决方案

    解决方法: Internet选项->安全->自定义级别->将文件下载到服务器时包含本地目录路径  启用就可以了.

  9. Scala - 处理时间(nscala-time - Joda Time的scala封装)

    GITHUB : https://github.com/nscala-time/nscala-time MAVEN : (注意选对scala版本) <dependency> <gro ...

  10. (转) sphinx 高亮显示搜索词

    http://hi.baidu.com/tewuapple/item/7a7bc34adbda24a8df2a9fe5  (转)