Codeforces Round #265 (Div. 1)
2 seconds
256 megabytes
standard input
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.
The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 100).
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.
1 3
1.0000000000
2 1
2.3333333333
10 2
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)的更多相关文章
- 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 ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断
http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...
- Codeforces Round #265 (Div. 2)
http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...
- Codeforces Round #265 (Div. 2) E
这题说的是给了数字的字符串 然后有n种的操作没次将一个数字替换成另一个字符串,求出最后形成的字符串的 数字是多大,我们可以逆向的将每个数推出来,计算出他的值和位数记住位数用10的k次方来记 1位就是1 ...
- 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 ...
随机推荐
- 关于React的赋值与调用方法
#关于React的赋值与调用方法 比如调用方法的时候我们可以这样来使用closeFrm() <div className = "infoFrm_close" onMouseO ...
- node.js0-5初级者
伴着<妈是心中的茉莉花> 这里,我用的sublime记事本,所以用的运行方法是终端.(后来发现git 可以省去cd切换目录). 安装node.js 官网说的很清楚. 这里我们可以在js文 ...
- Android使用MediaRecorder和Camera实现视频录制及播放功能整理
转载请注明出处:http://blog.csdn.net/woshizisezise/article/details/51878566 这两天产品经理向我丢来一个新需求,需要在项目里添加一个视频录制的 ...
- winform中显示标题,点击打开链接
效果:显示的是标题,但是点击打开的是链接 思路:定义一个类,将类实例化,向类中写入数据,再将类放到listbox中,设置listbox的显示分类为文本 前台:放入一个listbox控件 后台: pub ...
- VS2010中C++ 出现fatal error LNK1169: 找到一个或多个多重定义的符号
一般是函数重定义造成的 例如定义了两个 sum(x,y)函数
- iOS图片目录批量复制到android图片目录
复制shell脚本 #!/bin/bash for i in `ls` do for imgname in `ls $i | grep '^WM.*'` do echo $imgname cp $i/ ...
- C++类构造函数、析构函数运行机理
http://blog.sina.com.cn/s/blog_6fd68d5f0100n60h.html 前言--构造函数.析构函数的简单理解:1)构造函数---对象被创建时候调用的函数:2)析构函数 ...
- winhex 中磁盘大小与偏移
下图为c盘(活动分区).上方base offset为相对于整个硬盘的字节偏移量.partition 1中信息包括c盘开始扇区,总扇区数.partition 2 信息为扩展分区开始扇区和扇区数.由 P1 ...
- QT 图形视图框架
https://blog.csdn.net/qq769651718/article/details/79357936 使用QPushButton.QLabel.QCheckBox等构成GUI的控件或自 ...
- ucosii(2.89) 在Lpc1765移植中定时器的使用。
1,lpc1765的systicker register是24bit, cpu 频率64Mhz时候,注意不要设置systicker 的值超过24bit. 2, 使用timer 的callback函数, ...