Funny Funny Game
来源:互联网 发布:索尼降噪豆测评 知乎 编辑:程序博客网 时间:2024/05/21 17:20
Funny Funny Game
Time Limit: 1 Sec Memory Limit: 128 MBSubmissions: 12 Solved: 10
Description
Super Hanhan(SH) loves playing all kinds of little games very much. Today rocket323 recommends a new game to SH.
The game’s name is “Eating stones”, and it’s played like this: in a single round, the game system will randomly generate a sequence of N numbers(all of these N numbers are unique) representing the size of stones, and place them from left to right in a single line. Each time the player can choose one stone to eat, and then get a score of P points, which equal to number of remaining stones which are smaller than the chosen stone and to the left of the chosen stone.
SH wants to maximize the score he can get, however, he can’t figure out the best strategy to reach the goal. So he asks you(a talented programmer) for help.
Please help the poor SH find out the best strategy and tell him the expected scores he can get under this strategy.
Input
There are multiple cases.
The first line is an integer T representing the number of test cases.
The following T lines each line representing a test case. For each case there is exactly one line containing a single number N, representing the number of stones in the game. (1 <= N <= 1000000)
Output
For each test case, output a line containing the answer in the following format:
Case #K: X
K is the case number starting from 1, and X must be printed as a real number with two-digit precision, and the last decimal digit must be rounded.
Sample Input
213
Sample Output
Case #1: 0.00Case #2: 1.50
题目描述:给定n个石子从左往右,吃n次,每次吃一个石头,分数加上该石头左边还剩的石头数
求最后得分的期望
分析:其实暴力模拟这个问题并不难,而且存在着大量的重叠子问题
比如当前石头序列为n,那么我们这轮有n种选择,每一种选择的后继状态是一个n-1的子问题
第i种选择表示吃第i个石头,那么当前的得分为i,我们定义dp[x]为该规模下总得分
很容易知道 总的情况数有x!这么多,那么期望就是dp[x]/x!
第i个选择共有(x-1)!种后继情况,而该轮得分为x-1,于是我们只要再加上x-1规模下的总得分就可以了
最后暴力发现该序列是一个二阶等差数列,于是乎可以O(1)的获得答案,即便不找规律
其实对暴力程序稍作修改,同样可以得到满意的解答,注意到dp[x]=sum((x-1)!*(i-1)+dp[x-1])(1<=i<=x)
前面部分可以预处理,后面部分是死的,于是可以得到一个线性的解决方案
- Funny Funny Game
- Funny Funny Game(数学题)
- Funny Game
- funny
- funny
- funny
- funny
- funny
- funny
- 1087. A Funny Game
- 1087. A Funny Game
- A Funny Game
- A Funny Game
- poj2484 A Funny Game
- poj2599 A funny game
- 1087[A funny game]
- sicily 1087.Funny game
- 【poj2484】A Funny Game
- cap
- j2me的模仿写短信平台
- 在txt文件里进行查询(winform案例简单)
- 苹果第三季度美国数字音乐市场份额增长至66%
- c语言面试题-----指针篇
- Funny Funny Game
- 使用字符串作为函数模板的实参
- 通配符
- ARM与x86–蝶变ARM(力荐弯曲评论)
- j2me的ChoiceGroup 的运用
- lucene.net2.9搜索Demo
- 字符数组与字符指针的区别。
- 多个按钮样式下载
- union all 和 union的区别