fzu 2037 Maximum Value Problem
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的更多相关文章
- 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 ...
- maximum subarray problem
In computer science, the maximum subarray problem is the task of finding the contiguous subarray wit ...
- 动态规划法(八)最大子数组问题(maximum subarray problem)
问题简介 本文将介绍计算机算法中的经典问题--最大子数组问题(maximum subarray problem).所谓的最大子数组问题,指的是:给定一个数组A,寻找A的和最大的非空连续子数组.比如 ...
- 回溯法——最大团问题(Maximum Clique Problem, MCP)
概述: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题.最大团问题又称为最大独立集问题(Maximum Independent ...
- 贪心 FZU 2013 A short problem
题目传送门 /* 题意:取长度不小于m的序列使得和最大 贪心:先来一个前缀和,只要长度不小于m,从m开始,更新起点k最小值和ans最大值 */ #include <cstdio> #inc ...
- FZU 2218 Simple String Problem(简单字符串问题)
Description 题目描述 Recently, you have found your interest in string theory. Here is an interesting que ...
- FZU - 2218 Simple String Problem(状压dp)
Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...
- FZU - 2218 Simple String Problem 状压dp
FZU - 2218Simple String Problem 题目大意:给一个长度为n含有k个不同字母的串,从中挑选出两个连续的子串,要求两个子串中含有不同的字符,问这样的两个子串长度乘积最大是多少 ...
- FZU 2215 Simple Polynomial Problem(简单多项式问题)
Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...
随机推荐
- [Form Builder]:CREATE_GROUP Built-in
Description Creates a non-query record group with the given name. The new record group has no colum ...
- uboot源码解析
实例:1.3.4版本at91sam系列 GPIO部分: 一.初始化: include\asm-arm\arch-at91sam9\gpio.h 1.同一引脚的复用设置 2.输入输出初始化寄存器 3.得 ...
- ImageButton 在IE 10 下的异常
最近在项目中遇到一个棘手问题,在IE10中,一些图片按钮点了毫无反应,其他浏览器(包括IE9)都正常:查看后台,发现如下异常信息: Input string was not in a correct ...
- 20160324 javaweb 之request
package com.dzq.servlet; import java.io.IOException; import javax.servlet.ServletException; import j ...
- 关于安卓应用(APK文件)的二次打包
http://blog.csdn.net/baiyuliang2013/article/details/40426681 很多开发者,不管是个人或是公司都不太注重自己开发的应用的安全性,即是 否会被不 ...
- ACM——A + B Problem (2)
A + B Problem (2) 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:2600 测试通过:137 ...
- 误删除了Oracle的dbf文件后的解决方法
问题描述: 误删除Oracle数据库的dbf文件,在启动和关闭数据库是会提示错误. startup启动数据库时提示: ORA-01157:无法标识/锁定数据文件 ORA-01110:数据文件:‘... ...
- spring学习笔记之spring框架本质
Spring框架的本质是,开发者在Spring配置文件中使用XML元素进行配置,实际驱动Spring执行相应的代码: 使用<bean.../>元素,实际启动Spring执行无参或有参构造函 ...
- bzoj1004:[HNOI2008]Cards
思路:由于题目给出了置换,又要求本质不同的方案数,考虑使用Burnside引理,Burnside引理即通过所有置换和原来相同的方案数之和除以方案数总数,而对于某一个置换要使置换后得到的与原来的相同,就 ...
- Gradle教程之任务管理
简要概述依赖管理 不算完美的依赖管理技术 自动管理依赖的重要性 自动依赖管理面临的挑战 声明依赖 外部模块依赖 文件依赖 配置远程仓库 这一章我将介绍Gradle对依赖管理的强大支持,学习依赖分组和定 ...