D. World of Darkraft - 2
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Roma found a new character in the game "World of Darkraft - 2". In this game the character fights monsters, finds the more and more advanced stuff that lets him fight stronger monsters.

The character can equip himself with k distinct types of items. Power of each item depends on its level (positive integer number). Initially the character has one 1-level item of each of the k types.

After the victory over the monster the character finds exactly one new randomly generated item. The generation process looks as follows. Firstly the type of the item is defined; each of the k types has the same probability. Then the level of the new item is defined. Let's assume that the level of player's item of the chosen type is equal to t at the moment. Level of the new item will be chosen uniformly among integers from segment [1; t + 1].

From the new item and the current player's item of the same type Roma chooses the best one (i.e. the one with greater level) and equips it (if both of them has the same level Roma choses any). The remaining item is sold for coins. Roma sells an item of level x of any type for xcoins.

Help Roma determine the expected number of earned coins after the victory over n monsters.

Input

The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 100).

Output

Print a real number — expected number of earned coins after victory over n monsters. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 9.

Examples
input
1 3
output
1.0000000000
input
2 1
output
2.3333333333
input
10 2
output
15.9380768924

打怪升级之概率dp,窝不会啊,复杂度怎么够啊,内存也吃不消,还要精确到1e-9

所以直接省去了一些操作

官方推导,世界突然变得明朗起来

#include<bits/stdc++.h>
using namespace std;
double E[][];
int main()
{
int n,k;
cin>>n>>k;int f1=,f2=;
for(int i=n-; i>=; i--)
{
for(int j=; j<; j++)
E[f1][j]=E[f2][j]*(j*./(j+)/k+(k-)*./k)+(j*./+j*./(j+))/k+./(j+)*E[f2][j+]/k;
swap(f1,f2);
}
printf("%.10f\n",k*E[f2][]);
return ;
}

Codeforces Round #265 (Div. 1)的更多相关文章

  1. Codeforces Round #265 (Div. 1) C. Substitutes in Number dp

    题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...

  2. Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子

    http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...

  3. Codeforces Round #265 (Div. 2) E. Substitutes in Number

    http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...

  4. Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断

    http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...

  5. Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串

    http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...

  6. Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断

    http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...

  7. Codeforces Round #265 (Div. 2)

    http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...

  8. Codeforces Round #265 (Div. 2) E

    这题说的是给了数字的字符串 然后有n种的操作没次将一个数字替换成另一个字符串,求出最后形成的字符串的 数字是多大,我们可以逆向的将每个数推出来,计算出他的值和位数记住位数用10的k次方来记 1位就是1 ...

  9. Codeforces Round #265 (Div. 2) B. Inbox (100500)

    Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others ...

随机推荐

  1. 在WIN7、WIN8中,将快捷方式锁定到任务栏,C#

    其实很简单,使用 API 函数 ShellExecute,就可以解决这个问题. 首先添加引用 using System.Runtime.InteropServices; 代码如下: using Sys ...

  2. asp也玩三层架构(有源代码)

    实体类 <% Class UserInfo Private mintId Public Property Let UserId(intUserId) mintId = intUserId End ...

  3. python第一模块基础语法

    一·python和各大高级语言的优缺点比较 1.c语言开发效率低 2.c++开发效率高于c语言,低于java,python. 3.java代码臃肿,设计复杂,库繁杂量多. 4.PHP应用领域单一,且运 ...

  4. Flask信号流程

    首先先我们来看看Flask里面的信号是什么样的,我们可以找到一个叫signals.py的文件 这里面是所有定义了的后面请求流程中会用到的信号 二.哪些地方用到了信号 1.请求app上下文时执行的,在执 ...

  5. WebStorm 配置less

    1.打开Webstorm的Setting 搜索,watch 找到 File watch,点击右侧加号添加Less. 2.配置, working directory. Output paths

  6. Invalid bound statement (not found): com.ros.dao.LogMapper.insert

    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ros.dao.LogMapp ...

  7. Django auth权限

    创建超级管理员命令 python manage.py createsuperuser --username hello 检查和校验用户 from django.contrib import auth ...

  8. CAD交互绘制圆形批注(网页版)

    js中实现代码说明: 动态拖放时的绘制事件: function DoDynWorldDrawFun(dX,dY,pWorldDraw,pData) { //自定义实体的GUID标识符 var sGui ...

  9. java程序-类的高级特性

    创建Employee类,在类中定义三个属性:编号,姓名,年龄,然后在构造方法里初始化这三个属性,最后在实现接口中的定义的CompareTo方法,将对象按编号升序排列. 代码如下:(程序可能有些错误,方 ...

  10. js中声明函数的三种方式

    己亥年  庚午月 癸巳日  宜入宅 忌婚嫁 函数声明方式 声明 : function first(){}: 调用:first() 函数表达式声明方式   声明: var second=function ...