Codeforces 235B Let's Play Osu! 概率dp(水

题目链接:点击打开链接

给定n表示有n个格子

下面每个格子为O的概率是多少。

对于一段连续 x 个O的价值就是 x*x ;

问:

获得的价值的期望是多少。

思路:

把公式拆一下。。

#include <cstdio>
const int N = 100005;
double dp[N][2], p[N];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) {
		scanf("%lf", &p[i]);
	}
	dp[0][0] = dp[0][1] = 0;
	double ans = 0;
	for(int i = 1; i <= n; i ++) {
		dp[i][0] = dp[i-1][0] * p[i] + p[i];
		dp[i][1] = dp[i-1][1] + 2 * dp[i][0] - p[i];
	}
	printf("%.10f\n", dp[n][1]);
	return 0;
}

Codeforces 235B Let's Play Osu! 概率dp(水

时间: 2025-01-10 05:17:18

Codeforces 235B Let's Play Osu! 概率dp(水的相关文章

codeforces 235B Let&#39;s Play Osu! 概率dp

题意:给定n表示有n个格子,下面每个格子为O的概率是多少.对于一段连续 x 个O的价值就是 x^2 ;求获得的价值的期望是多少. 思路:n^2=n×(n-1)+n,设ai为第i段连续O的长度,∑ai^2 = ∑[ ai+ ai*(ai-1) ] = ∑ ai*(ai-1) + ∑ai = ∑ C(ai, 2)*2 + ∑ai,那么问题可以转 化为求长度大于1的连续段数*2+O的个数的总期望. ∑ai我们可以理解为O的总个数,所以它的期望为∑pi: C(ai, 2)*2我们可以认 为是连续ai个O

Codeforces 235B Let&#39;s Play Osu! (概率dp求期望+公式变形)

B. Let's Play Osu! time limit per test:2 seconds memory limit per test:256 megabytes You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us deno

Codeforces 235B. Let&#39;s Play Osu!

235B - Let's Play Osu! Let us take a deep look in how this score is calculated. for a n long 'O' block, they contribute n2 to answer. Let us reformat this problem a bit and consider the following problem. For each two 'O' pair which is no 'X' between

Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃圾,大哥拿来了一袋老鼠,其中有w只白老鼠和b只黑老鼠.胡小兔先抓,先抓到白老鼠的人赢. 每次学姐抓完老鼠之后,总会有另外一只老鼠从袋子里自己跑出来(这只老鼠不算任何人抓的),而胡小兔抓老鼠时则不会发生这样的事. 每次袋子里的每只老鼠被抓到的概率相等,当有一只老鼠跑出来的时候,每只老鼠跑出来的几率也相

Codeforces Div.301D Bad Luck Island(概率dp+记忆化搜索)

一道概率dp问题. 题目链接:http://codeforces.com/contest/540/problem/D 题目大意:一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j][k]来存储i个石头,j个剪刀,k个布时,某物种的存活概率,共dp三次,算出三个物种分别的概率. 首先,我们需要把对应想求的物种概率初始化,这里以石头为例,那么对于i从1到r,不难理解dp[i][0][0]=

Codeforces 167B Wizards and Huge Prize 概率dp(水

题目链接:点击打开链接 题意: 给定n个对手,至少要击败其中 l 个人,现在有口袋容量为 k 下面n个数字表示击败这个人的概率 下面n个数字(若为-1表示击败这个人可以获得一个金币,若>0则表示可以增加口袋容量为这个数字) 问: 至少击败其中的l个人,且获得的总口袋容量 >= 获得的金币个数 的概率是多少.(即任何时候金币都不能放不下) 思路: 概率dp 要注意的是有可能口袋容量是负数,但最后的时候变成了正数,所以要给口袋容量都+N, #include <iostream> #in

LightOJ1030 Discovering Gold 概率DP 水题

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1.

13年山东省赛 The number of steps(概率dp水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud The number of steps Time Limit: 1 Sec  Memory Limit: 128 M Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two ro

hdu3722Card Game 概率dp水题

//3中天气前一天天气为i转为第二天天气为j的概率为p[i][j] //问第一天天气为i,n天后天气为j的概率 //dp[i][j][k]在第一天天气为j的情况下第n天的天气为j的概率 //dp[i][j][k] += dp[i-1][j][s]*dp[1][s][k] ; #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int maxn = 1010 ;