Problem

给定一个数x,有p%的概率乘2,有1-p%的概率加1,问操作k次,其二进制数下末尾零的个数的期望。

Solution

每次操作只会影响到最后的8位

我们用dp[i][j]表示i个操作后,后面的操作还需要加j

对于+1的操作:dp[i][j-1]+=dp[i-1][j](1-p)

对于
2的操作:dp[i][j2]+=(dp[i-1][j]+1)p

Notice

需要预处理

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define reg register int
#define rep(i, a, b) for (reg i = a; i <= b; i++)
#define per(i, a, b) for (reg i = a; i >= b; i--)
#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)
const int INF = 1e9;
const double eps = 1e-6, phi = acos(-1.0);
ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}
ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}
void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}
double p;
int x, k;
double f[205][205];
int sqz()
{
int x = read(), k = read();
scanf("%lf", &p), p /= 100;
rep(i, 0, k)
{
int t = x + i;
while (1)
{
if (t & 1) break;
f[0][i]++;
t /= 2;
}
}
rep(i, 1, k)
{
memset(f[i], 0, sizeof f[i]);
rep(j, 0, k)
{
if (j) f[i][j - 1] += f[i - 1][j] * (1 - p);
if (j * 2 <= k) f[i][j * 2] += (f[i - 1][j] + 1) * p;
}
}
printf("%.10lf\n", f[k][0]);
}

[Codeforces441E]Valera and Number的更多相关文章

  1. [CodeForces-441E]Valera and Number

    题目大意: 给你一个数x,进行k次操作: 1.有p%的概率将x翻倍: 2.有1-p%的概率将x加1. 问最后二进制下x末尾0个数的期望. 思路: 动态规划. 由于k只到200,所以每次修改只与最后8位 ...

  2. 【Codeforces441E】Valera and Number [DP]

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

  3. CodeForces - 441E:Valera and Number (DP&数学期望&二进制)

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

  4. CF 441E Valera and Number

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

  5. [CF441E]Valera and Number

    题意:给定$x,k,p$和一份伪代码,伪代码大致是循环$k$次,每次有$p\%$的概率把$x$乘$2$,有$(100-p)\%$的概率把$x$加$1$,问最后在二进制下$x$的末尾期望$0$个数 鸽了 ...

  6. Codeforces刷题计划

    Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1 ...

  7. Codeforces Round 252 (Div. 2)

    layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  8. CF 369C . Valera and Elections tree dfs 好题

    C. Valera and Elections   The city Valera lives in is going to hold elections to the city Parliament ...

  9. [Codeforces Round #237 (Div. 2)] A. Valera and X

    A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. C++重载操作符自增自减

    #include <iostream> using namespace std; class Test { friend ostream& operator<<(ost ...

  2. python IO 多路复用

    一.epoll epoll 参考链接: https://www.cnblogs.com/Alanpy/articles/5125986.html epoll  参考链接: https://www.cn ...

  3. C# 调用C++的dll 那些事

    之前从来没搞过C++,最近被安排的任务需要调用C++的接口,对于一个没用过 Dependency 的小白来说,原本以为像平时的Http接口那样,协议,端口一定义,方法参数一写就没事,结果踩了无数的坑. ...

  4. vue mand-mobile ui加class不起作用的问题 css权重问题

    vue mand-mobile ui加class不起作用的问题 css权重问题组件的样式优先权比自己定的class高多加几层权重才行,要直接用样式覆盖也可以在前面多加几层class,定位更精确了才会覆 ...

  5. 基于ABP模块组件与依赖注入组件的项目插件开发

    注意,阅读本文,需要先阅读以下两篇文章,并且对依赖注入有一定的基础. 模块系统:http://www.cnblogs.com/mienreal/p/4537522.html 依赖注入:http://w ...

  6. 第六节 DOM操作应用

    创建.插入和删除元素 创建DOM元素: createElement(标签名); //创建一个节点 appendChild(节点); //追加一个节点 例如:document.body.appendCh ...

  7. 谷歌浏览器怎样把网页全部内容保存为.mhtml文件?

    Chrome保存.mhtml网页文件的方法: 在 Chrome 地址栏中键入chrome://flags,回车, 在页面搜索栏输入mhtml 把“Save Page as MHTML”项修改为 Ena ...

  8. 获取从库Seconds_Behind_Master监控主从同步

    #!/bin/bash now_date=`date "+%Y-%m-%d,%H:%M:%S"` flag_old=`cat /home/oracle/scripts/flag.t ...

  9. Bootstrap3基础 table-striped 表格实现隔行换色(浅灰色与白色交替)

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  10. 【Bilinear interpolation】双线性插值详解(转)

           最近在做视频拼接的项目,里面用到了图像的单应性矩阵变换,在最后的图像重映射,由于目标图像的坐标是非整数的,所以需要用到插值的方法,用的就是双线性插值,下面的博文主要是查看了前辈的博客对双 ...