Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below:

//input: integers x, k, p
a = x;
for(step = 1; step <= k; step = step + 1){
rnd = [random integer from 1 to 100];
if(rnd <= p)
a = a * 2;
else
a = a + 1;
} s = 0; while(remainder after dividing a by 2 equals 0){
a = a / 2;
s = s + 1;
}

Now Valera wonders: given the values x, k and p, what is the expected value of the resulting number s?

Input

The first line of the input contains three integers x, k, p (1 ≤ x ≤ 109; 1 ≤ k ≤ 200; 0 ≤ p ≤ 100).

Output

Print the required expected value. Your answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

Examples

Input
1 1 50
Output
1.0000000000000
Input
5 3 0
Output
3.0000000000000
Input
5 3 25
Output
1.9218750000000

题意:给定X,现在进行K轮操作,每一轮有P%的概率加倍,(100-P)%的概率加一,问K轮之后的X的因子2的次数。

思路:首先一个数X中2的因子个数=转化为二进制后末尾0的个数=__builtin_ctz(X);题解给的四维DP比较麻烦,这里有一种比较难以想到,但是不难理解的二维DP。

用dp[i][j],表示X+j进行i轮操作后的因子2的幂。 那么答案就是dp[K][0];

那么转移就是:

dp[i][j]+=(dp[i-1][j+1])*(1.0-P);   即第一次操作为+1;
            dp[i][j<<1]+=(dp[i-1][j]+1)*P;  即第一次操作为*2;

虽然乘法的话第二维会加倍增长,但加法的话第二维会减小1,所以最小影响到dp[K][0]的最大第二维就是K,而不用维护所有的dp[][j],即j<=K;

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std; //*2 P
double dp[][],P;
int main()
{
int X,K;
scanf("%d%d%lf",&X,&K,&P); P/=100.0;
rep(i,,K) dp[][i]=__builtin_ctz(X+i);
rep(i,,K){
rep(j,,K){
dp[i][j]+=(dp[i-][j+])*(1.0-P);
dp[i][j<<]+=(dp[i-][j]+)*P;
}
}
printf("%.10lf\n",dp[K][]);
return ;
}

CodeForces - 441E:Valera and Number (DP&数学期望&二进制)的更多相关文章

  1. 【Codeforces441E】Valera and Number [DP]

    Valera and Number Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample Input 5 3 ...

  2. CF 441E Valera and Number

    CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个 ...

  3. LightOj 1030 - Discovering Gold(dp+数学期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...

  4. BZOJ1076 [SCOI2008]奖励关 【状压dp + 数学期望】

    1076: [SCOI2008]奖励关 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 3074  Solved: 1599 [Submit][Sta ...

  5. bzoj1415 [Noi2005]聪聪和可可【概率dp 数学期望】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1415 noip2016 D1T3,多么痛的领悟...看来要恶补一下与期望相关的东西了. 这是 ...

  6. P4707-重返现世【dp,数学期望,扩展min-max容斥】

    正题 题目链接:https://www.luogu.com.cn/problem/P4707 题目大意 \(n\)个物品,每次生成一种物品,第\(i\)个被生成的概率是\(\frac{p_i}{m}\ ...

  7. 【BZOJ】1076: [SCOI2008]奖励关(状压dp+数学期望)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1076 有时候人蠢还真是蠢.一开始我看不懂期望啊..白书上其实讲得很详细的,什么全概率,全期望(这个压 ...

  8. CF 148D D. Bag of mice (概率DP||数学期望)

    The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests ...

  9. [poj2096] Collecting Bugs【概率dp 数学期望】

    传送门:http://poj.org/problem?id=2096 题面很长,大意就是说,有n种bug,s种系统,每一个bug只能属于n中bug中的一种,也只能属于s种系统中的一种.一天能找一个bu ...

随机推荐

  1. Hotspot的minor GC

    内容来自<java性能优化>. 上图展示了Hotspot minor GC的过程:eden中的存活对象和from中"不够老"的对象,被移动到to中,from中" ...

  2. TLS与SSL之间关系——SSL已经被IEFT组织废弃,你可以简单认为TLS是SSL的加强版

    TLS与SSL之间关系 原文地址:SSL vs. TLS - What's the Difference? from:https://juejin.im/post/5b213a0ae51d4506d4 ...

  3. Let's Encrypt 免费通配符 SSL 证书申请教程——但是也需要email,域名所有权等,如果是黑产用的话会这样用吗?会不会暴露自己身份???

    Let's Encrypt 免费通配符 SSL 证书申请教程 from:https://blog.csdn.net/English0523/article/details/79608464 2018 ...

  4. Oracle awr报告生成操作步骤

    1.登录主机切换到oracle用户 ssh root@192.168.220.128 su - oracle 2.以sysdba身份登录数据库 sqlplus / as sysdba 3.执行@?/r ...

  5. [转]使用CMS垃圾收集器产生的问题和解决方案

    在之前的一篇文章<CMS vs. Parallel GC>里通过实验的方式对比了并行和并发GC的优缺点,在文章结尾提到,CMS并行GC是大多数应用的最佳选择,然而, CMS并不是完美的,在 ...

  6. 使用MongoDB数据库(1)(三十五)

    MongoDB简介 MongoDB是一个基于分布式文件存储的数据库,它是一个介于关系数据库和非关系数据库之间的产品,其主要目标是在键/值存储方式(提供了高性能和高度伸缩性)和传统的RDBMS系统(具有 ...

  7. python(4)之字典

    字典的操作方式如下: info={ 'stu1101':"xiaohai", 'stu1102':'liming', 'stu1103':"heima", } ...

  8. 机器学习---笔记----numpy和math包中的常用函数

    本文只是简单罗列一下再机器学习过程中遇到的常用的数学函数. 1. math.fabs(x): 返回x的绝对值.同numpy. >>> import numpy >>> ...

  9. Eclipse集成Tomcat插件(特别简单)

    . 只需要一个jar包 复制到eclipse/plugins文件夹下,重启Eclipse即可看到如下三只小猫 1.修改Tomcat (1)Tomcat version:版本 (2)Tomcat Hom ...

  10. 查找xml中的接口名及涉及表名并输出

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- import xml.dom.minidom  #该模块被用来处理xml文件 import re #正则表 ...