fzu 2037 Maximum Value Problem(规律? 递推)
来源:互联网 发布:天则经济研究 知乎 编辑:程序博客网 时间:2024/05/23 13:03
Problem Description
Let’s start with a very classical problem. Given an array a[1…n] of positive numbers, if the value of each element in the array is distinct, how to find the maximum element in this array? You may write down the following pseudo code to solve this problem:
function find_max(a[1…n])
max=0;
for each v from a
if(max<v)
max=v;
return max;
However, our problem would not be so easy. As we know, the sentence ‘max=v’ would be executed when and only when a larger element is found while we traverse the array. You may easily count the number of execution of the sentence ‘max=v’ for a given array a[1…n].
Now, this is your task. For all permutations of a[1…n], including a[1…n] itself, please calculate the total number of the execution of the sentence ‘max=v’. For example, for the array [1, 2, 3], all its permutations are [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2] and [3, 2, 1]. For the six permutations, the sentence ‘max=v’ needs to be executed 3, 2, 2, 2, 1 and 1 times respectively. So the total number would be 3+2+2+2+1+1=11 times.
Also, you may need to compute that how many times the sentence ‘max=v’ are expected to be executed when an array a[1…n] is given (Note that all the elements in the array is positive and distinct). When n equals to 3, the number should be 11/6= 1.833333.
Input
The first line of the input contains an integer T(T≤100,000), indicating the number of test cases. In each line of the following T lines, there is a single integer n(n≤1,000,000) representing the length of the array.
Output
For each test case, print a line containing the test case number (beginning with 1), the total number mod 1,000,000,007
and the expected number with 6 digits of precision, round half up in a single line.
Sample Input
Sample Output
Source
2011年全国大学生程序设计邀请赛(福州)#include <stdio.h>#include <string.h>#define MOD 1000000007const int N = 1000005;int t, n;long long f[N], jie[N];double p[N];void table() { jie[0] = 1; f[0] = 0; p[0] = 0; for (long long i = 1; i <= 1000000; i ++) {jie[i] = jie[i - 1] * i % MOD;f[i] = (f[i - 1] * i + jie[i - 1]) % MOD;p[i] = p[i - 1] + (1.0 / i); }}int main() { table(); scanf("%d", &t); int cas = 0; while (t--) {scanf("%d", &n);printf("Case %d: %lld %.6lf\n", ++cas, f[n], p[n]); } return 0;}
- fzu 2037 Maximum Value Problem(规律? 递推)
- Maximum Value Problem FZU 2037 找规律 递推
- FZU 2037 Maximum Value Problem【递推】
- FZU 2037- Maximum Value Problem(规律题)
- fzu 2037 Maximum Value Problem(递推)
- FZU2037 Maximum Value Problem 规律 + 递推
- FZU 2037Maximum Value Problem (打表预处理/找规律)
- FZU 2037 Maximum Value Problem
- Maximum Value Problem FZU
- 找规律 递推
- 递归 递推 规律
- FZU 2238 Daxia & Wzc's problem【规律+lucas】
- HDU2058 找规律+递推
- 51nod1202-递推&规律
- URAL 1079 Maximum 递推
- FZU 2147(找规律)
- Maximum Value
- Maximum Value
- 黑马程序员_java基础加强之多线程
- 一个字符数组,里面的字符可能是a-z、A-Z、0-9.现在要求对数组进行排序,要求所有小写字符放在最前面,所有大写字符放在中间,所有数字放在最后,而且各部分内部分别有序(创新工场)
- linux shell “(())” 双括号运算符使用
- mysql事务视图触发器
- 第13章 基于MATLAB的语音识别系统
- fzu 2037 Maximum Value Problem(规律? 递推)
- iOS手势识别的详细使用拖动,缩放,旋转,点击,手势依赖,自定义手势
- Java代码质量检测评估工具PMD在线安装
- nginx无痛升级并增加nginx-gridfs模块支持
- 轻松掌握object类
- 13.4 非特定人语音识别算法——HMM
- 鬼哥Csdn免积分在线下载器v10.0-网页版
- 调度子系统4_负载均衡(一)
- 几种开源网络爬虫的简单比较