CF 441E

Description

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

Solution

设\(f[i][j]\)为执行第\(i\)次后\(x + j\)末尾期望\(0\)的个数

加一:$f[i + 1][j - 1] = f[i + 1][j - 1] + (100 - p)% * f[i][j]; $

乘二:\(f[i + 1][j * 2] = f[i + 1][j * 2] + p\% * (f[i][j] + 1);\)

#include<bits/stdc++.h>
using namespace std;
int x, k;
double p, p1;
double f[300][300];
int main() {
scanf("%d%d%lf", &x, &k, &p);
p /= 100, p1 = 1.0 - p;
for (int i = 0; i <= k; i ++)
for (int j = x + i; j % 2 == 0; j /= 2)
f[0][i] ++;
for (int i = 0; i < k; i ++)
for (int j = 0; j <= k; j ++) {
if (j)
f[i + 1][j - 1] += p1 * f[i][j]; // + 1
if (j * 2 <= k)
f[i + 1][j * 2] += p * (f[i][j] + 1); // * 2
}
printf("%.10f\n", f[k][0]);
return 0;
}

CF 441E Valera and Number的更多相关文章

  1. 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 ...

  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. 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 ...

  4. CF#231DIV2:A Good Number

    Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a numbe ...

  5. CF 724 G. Xor-matic Number of the Graph

    G. Xor-matic Number of the Graph 链接 题意: 给定一个无向图,一个interesting的三元环(u,v,s)满足,从u到v的路径上的异或和等于s,三元环的权值为s, ...

  6. cf B Very Beautiful Number

    题意:给你两个数p和x,然后让你找出一个长度为p的数,把它的最后移到最前面之后得到的数是原来数字的x倍,有很多这样的数取最小. 思路:枚举最后一位,然后就可以推出整个的一个数,然后比较得到的数的第一个 ...

  7. cf C. George and Number

    http://codeforces.com/problemset/problem/387/C 题意:给你一个大数,让你求个集合,可以通过操作得到这个数,求集合中个数最大值,操作 :从集合中任意取两个数 ...

  8. cf E. Valera and Queries

    http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. ...

  9. cf D. Valera and Fools

    http://codeforces.com/contest/369/problem/D 标号最小的两个人会有四种状态:a活b活,a死b活,a活b死,a死b死:按照这四种状态dfs就可以求出最后的数量. ...

随机推荐

  1. 如何在windows系统下安装swoole

    swoole框架是一个很神奇很厉害的框架,它弥补了PHP的本身的一些不足之处.其实swoole确切的说是一个使用C语言编写的PHP扩展,并且这个扩展不能够在windows系统使用,但是就目前的开发环境 ...

  2. Django 加载 app 中的urls

    在 blog app 下创建 urls.py, 定义该 app 下自有的 url : new/story from blog import views from django.conf import ...

  3. css的三种书写方式

    一.内联样式 <p style="color: sienna; margin-left: 20px"> This is a paragraph </p> 二 ...

  4. 基于Android的模拟点击探索

    前言 压力测试中,一般会用到自动化测试.准备写一个APP,可以记录屏幕上的点击事件,然后通过shell命令来模拟自动执行.shell指令,比较容易实现.那么,关键的一步是获取点击的坐标.对于Andro ...

  5. RabbitMQ for Mac OS Install

    使用brew来安装 RabbitMQ brew install rabbitmq 执行看到如下命令: Updating Homebrew... ==> Auto-updated Homebrew ...

  6. C#零基础入门-0-开发工具

    Visual Studio sharpDevelop:http://www.icsharpcode.net/OpenSource/SD/Download/ Visual Studio Express

  7. 关闭windows系统的危险端口,命令行

    防火墙启用,增加禁用端口提供给外部访问 @echo off color E2 title 关闭常见的危险端口 echo 正在开启Windows防火墙 echo. netsh advfirewall s ...

  8. Postgres中文分词

    环境 CentOS Linux release 7.2.1511 (Core) 安装Postgres 安装postgres很简单 yum安装 sudo yum install postgresql-s ...

  9. 在chrome 怎么通过ajax请求加载本地文件

    在chrome下面用Jquery 的load方法加载本地的html文件时会报错 我百度了一下是因为 谷歌浏览器内核为了安全机制,不允许这样方式访问其他页面,但是可以通过加 --enable-file- ...

  10. Aspnet mvc移除WebFormViewEngine

    为了提高mvc的速度,在Global.asax中移除WebFormViewEngine protected void Application_Start() { RemoveWebFormEngine ...