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

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][j*2]+=(dp[i-1][j]+1)*p Notice 需要预处理 Code #include<cmath> #include<cstdio> #include…
题目大意: 给你一个数x,进行k次操作: 1.有p%的概率将x翻倍: 2.有1-p%的概率将x加1. 问最后二进制下x末尾0个数的期望. 思路: 动态规划. 由于k只到200,所以每次修改只与最后8位有关. f[i][x][y][z]表示操作次数为i时,末尾8为表示的数字为x,第9位为y,第9位及以上和第9位数字连续相同的长度. 对于两种情况分别转移,注意特判超过8位的进位. 最后计算期望的时候,可以枚举第一维为k的所有状态,然后通过状态可以直接计算出末尾0的数量,乘上概率即可. #includ…
Valera and Number Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample Input 5 3 25 Sample Output 1.9218750000 HINT Solution 考虑运用DP. Code #include<iostream> #include<string> #include<algorithm> #include<cstdio>…
Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below: //input: integers x, k, pa = 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…
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 +…
题意:给定$x,k,p$和一份伪代码,伪代码大致是循环$k$次,每次有$p\%$的概率把$x$乘$2$,有$(100-p)\%$的概率把$x$加$1$,问最后在二进制下$x$的末尾期望$0$个数 鸽了好久...今天来补一下 设$f_{i,j}$表示循环$i$次后$x+j$的末尾期望$0$个数 乘$2$:相当于把最后加上的$j$也乘$2$,所以$f_{i+1,2j}+=\dfrac{p}{100}(f_{i,j}+1)$ 加$1$:相当于上一轮加$1$,所以$f_{i+1,j}+=(1-\dfra…
Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1,每个数出现2~5次) [Codeforces441E]441E - Valera and Number:期望DP:(p%概率*2,(1-p%)概率+1,最后质因子中2的个数的期望) [Codeforces542E]542E - Playing on Graph:结论 + Bfs + Dfs:(用给定方式…
layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces - 群论 --- 传送门 A.Valera and Antique Items (签到) 题意 如果当前钱数比一组数中最小的还要大就+1 思路 直接模拟 #include<bits/stdc++.h> using namespace std…
C. Valera and Elections   The city Valera lives in is going to hold elections to the city Parliament. The city has n districts and n - 1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's…
A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn…