uva11176 - Winning Streak 数学期望 DP

uva1451 - Average 单调队列维护下凸曲线 A DNA sequence consists of four letters, A, C, G, and T. The GC-ratio of a DNA sequence is the number of Cs and Gs of the sequence divided by the length of the sequence. GC-ratio is important in gene 阅读详情

Problem B
Winning Streak
Input:
Standard Input

Output: Standard Output

 

"You can run onfor a long time,
sooner or later God'll cut you down."

– Traditional folksong

Mikael likes to gamble,and as you know, you can place bets on almost anything these days. A particularthing that has recently caught Mikael's interest isthe length of the longest winning streak of a team during a season (i.e. thehighest number of consecutive games won). In order to be able to make smarterbets, Mikael has asked you to write a program to helphim compute the expected value of the longest winning streak of his favourite teams.

In general, the probability that a team wins agame depends on a lot of different factors, such as whether they're the hometeam, whether some key player is injured, and so on. For the first prototype ofthe program, however, we simplify this, and assume that all games have the samefixed probability p of being won, and that the result of a game doesnot affect the win probability for subsequent games.

The expected value of the longest streak is theaverage of the longest streak in all possible outcomes of all games in aseason, weighted by their probability. For instance, assume that the seasonconsists of only three games, and thatp = 0.4. There are eightdifferent outcomes, which we can represent by a string of 'W':s and 'L':s,indicating which games were won and which games were lost (for example, 'WLW' indicates that the team won the firstand the third game, but lost the second). The possible results of the seasonare:

Result

LLL

LLW

LWL

LWW

WLL

WLW

WWL

WWW

Probability

0.216

0.144

0.144

0.096

0.144

0.096

0.096

0.064

Streak

0

1

1

2

1

1

2

3

In this case, the expected length of the longestwinning streak becomes 0.216·0 + 0.144·1 + 0.144·1 + 0.096·2 + 0.144·1 +0.096·1 + 0.096·2 + 0.064·3 = 1.104

Input

Several test cases (at most 40),each containing an integer 1 ≤ n ≤ 500 giving the numberof games in a season, and a floating point number 0 ≤p ≤1, the win probability. Input is terminated by a case where n = 0,which should not be processed.

 

Output

For each test case, give the expected length of the longestwinning streak. The answer should be given as a floating point number with anabsolute error of at most 10-4.

SampleInput                              Output for Sample Input

3 0.4
10 0.75
0 0.5

 

1.104000
5.068090

 


  N个字母,只能是W和L,出现W的概率是P,出现L的概率是1-P,streak是这N个字母中W最长连续个数,问streak的期望。

  话说这个题真的很难想啊。。

  用dp[i][j]表示前i个字母streak不超过j的概率。那是不是dp[i][j]就等于dp[i-1][j]减去其中由于增加了第i个而使streak大于j的情况的概率。也就是第i-j到第i个(共j+1个)都是W,i-j-1位置上是L,i-j-1之前的最长连续不超过j。也就是dp[i][j]=dp[i-1][j]-P^(j+1)*(1-P)*dp[i-j-2][j],当然这是在j+1<i的情况下,如果j+1==i,dp[i][j]=dp[i-1][j]-P^(j+1),如果j+1>i,dp[i][j]=dp[i-1][j]。最后dp[N][i]-dp[N][i-1]就是streak为i的概率。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int N;
double P,a[510],dp[510][510];
void init(){
    a[0]=1;
    for(int i=1;i<=N;i++) a[i]=a[i-1]*P;
}
void DP(){
    int i,j;
    for(i=0;i<=N;i++) dp[0][i]=1;
    for(i=1;i<=N;i++)
        for(j=0;j<=N;j++){
            dp[i][j]=dp[i-1][j];
            if(i-j==1) dp[i][j]-=a[i];
            else if(j+1<i) dp[i][j]-=a[j+1]*(1-P)*dp[i-j-2][j];
        }
}
int main(){
    freopen("in.txt","r",stdin);
    while(scanf("%d%lf",&N,&P),N){
        double ans=0;
        init();
        DP();
        for(int i=1;i<=N;i++) ans+=(dp[N][i]-dp[N][i-1])*i;
        printf("%.6lf\n",ans);
    }
    return 0;
}


uva10237 - Bishops 互不攻击的象 Problem B Bishops Input: standard input Output: standard output Time Limit: 4 seconds Memory Limit: 32 MB   A bishop is a piece used in thegame of chess which is played on a board of squa 阅读详情

相关推荐

实战指南:在华为防火墙上构建基于自签CA的SSL证书挑战式认证体系

本文详细介绍了在华为防火墙上构建基于自签CA的SSL证书挑战式认证体系的实战指南。通过自签CA证书生成、华为防火墙SSL VPN配置、客户端安装与测试等步骤,帮助企业实现更安全的远程办公接入方案,有效防范密码泄露风险。文章重点讲解了证书挑战登录的实现原理和配置细节,适用于企业网络安全建设。

weixin_32428571的博客 266

UVA11176 Winning Streak(概率)

题目 T(T<=40)组样例,每次给出赛季长度n(n<=500),和获胜(W)的概率p(0<=p<=1) 求最大连续胜场的期望,即对最大连续胜场为i时的概率pi,求和i*pi 思路来源 https://blog.csdn.net/yeyeyeguoguo/article/details/43534917 题解 本来想的是dp[i][j][k]表示当前第i次,历史最大连续W为j,当前连续W为k的方案数, O(n^3)怎么也降不下来,题解提供了一种新的dp思路 dp.

小衣同学的博客 296

什么是以太网链路聚合

以太网链路聚合技术通过将多个物理端口捆绑成逻辑端口,可显著提升网络性能。该技术能增加总带宽(各链路带宽之和)、提高可靠性(故障秒级切换)并实现智能负载分担。主要分为手工模式和基于LACP协议的动态模式,后者能检测链路故障更可靠。配置时需确保接口参数一致、模式匹配,适用于核心交换、服务器接入等场景。华为设备通过创建Eth-Trunk接口、指定LACP模式并添加成员接口即可完成部署。这项成熟技术能以低成本解决带宽瓶颈和可靠性问题,是构建高速稳定网络的关键方案。

lai_2020的博客 684

uva11176(dp + 概率)

题意: 有n场比赛,每场赢的概率是p,问连续赢的期望值 思路: f[i][j]表示的是第i次,连续赢的次数不超过j的所有情况的概率。如此以来 f[i][j] = f[i - 1][j]在扣掉不是该状态的情况的概率,即为多赢了一盘之后连续的情况超过j的情况,该情况只在末尾有j个连续赢的情况出现,所以要扣掉f[i][j] = f[i - 1][j] - f[i - 1 - j - 1][

潜水的程序猿 456

RH850_U2A系列HSM安全核开启但是固件未烧录导致无法启动也无法再烧入固件废板问题分析解决

hsm核导致的安全锁死补救方案

u011941262的博客 1749

行为验证码 AJ-Captcha 使用文档

AJ-Captcha验证码系统集成指南:需添加captcha-spring-boot-starter和Redis依赖,配置Redis连接。核心实现包括Redis缓存服务类CaptchaCacheRedisImpl(含设置、查询、删除验证码等方法)、SPI配置文件及Spring Boot配置类(配置验证码属性和Redis模板)。系统支持验证码生成、校验、防刷等安全功能,适用于Web应用安全验证场景。

千层冷面的博客 2144

uva 11176 Winning Streak

uva 11176 Winning Streak

@fei 704

CH455G数码管驱动与键盘扫描:I2C通信协议深度解析与实战代码

本文深度解析CH455G芯片的I2C通信协议,涵盖数码管驱动与键盘扫描功能的实战应用。通过详细讲解起始/停止信号、数据帧结构、应答机制及单片机代码实现,帮助开发者高效利用该芯片减少IO占用,提升嵌入式系统设计效率。

tea88的博客 1090

uva 11176 - Winning Streak(期望)

题目链接:uva 11176 - Winning Streak 题目大意:给出n和p,有n场比赛,获胜的概率为p,问说连续获胜的期望值是多少。 解题思路:昨天刚做了一道连续获胜的题目uva 10328 - Coin Toss,这不过这道题目始求期望,不过可以通过那道题目的思路求出概率,然后求期望就好求多了,dp[i][j]表示说在前i场比赛中,连续获胜的次数不超过j次,本题要结

不慌不忙、不急不躁 1810

开源鸿蒙具身机器人(ROS2框架):从内核驱动到智能算法的完整实践

本指导文档旨在为开发者提供完整的开源鸿蒙(OpenHarmony)具身机器人开发解决方案,涵盖从底层驱动到上层ROS2应用的全栈开发流程。文档结合OpenHarmony内核驱动移植技术和ROS2机器人操作系统,为具身机器人开发提供详细的技术指导。具身机器人(Embodied Robot)是指具有物理实体、能够感知环境并与之交互的智能机器人系统。感知-决策-执行闭环多模态传感器融合(视觉、听觉、触觉、力觉)实时环境感知与理解智能决策与规划精确运动控制执行具身智能特性物理世界交互能力。

m0_67505153的博客 1287

仿真学习系列(四十七):Sigrity仿真之直流压降与电流密度

在现代电子设计中,电源网络的设计和分析对于保证电路的稳定性至关重要。直流压降(IR-Drop)和电流密度是评估电源网络性能的关键参数,尤其是在高频和高速电路中。它们直接影响到设备的工作稳定性与效率。通过Sigrity的仿真工具,可以深入分析和优化这些电源特性,从而确保系统的可靠性。 本节将介绍直流压降和电流密度的基本概念,以及如何在Sigrity中使用PowerDC模块进行相关仿真。

案例文章,高速信号 526

UVA 11176 - Winning Streak(dp)

Problem B Winning Streak Input: Standard Input Output: Standard Output   "You can run on for a long time, sooner or later God'll cut you down." – Traditional folk song Mikael likes to gamble,

Remilia's 1800

结构光之相移法+多频外差的数学原理推导

‍论文:基于数字光栅投影的结构光三维测量技术与系统研究 [博]作者:李中伟 华中科技大学 2007功能:相移法:多频外差(三频N步相移法)01 相移法图1 待写入投影仪的理想N步相移条纹通常对于 步相移来说,生成第 幅条纹图像(如图1所示)的公式如下:402 Payment Required其中::背景光强:调制强度:像素点横向坐标:相移值图2 相机拍摄到的实际 N ......

3D视觉工坊 1200

求区间这种数的个数,这个数恰好等于k个互不相等的2的整数次幂之和 数位统计

Description 给定一个区间[x,y],求这个区间中满足下列条件的整数的个数:这个数恰好等于k个互不相等的2的整数次幂之和。例如x=15,y=20,k=2.则有且仅有下列三个数满足题意: 17=2^4+2^0; 18=2^4+2^1; 20=2^4+2^2;   (a^b代表是a的b次方) Input 接下来输入T行,每行对应一个样例,每行有3个整数x, y

1613

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

数位DP的记忆化搜索形式

数位DP的记忆化搜索形式比一般递推形式好写多了,而且一般不容易出错。   dfs求[0,n]有多少个符合的,先把n换成字符串形式。   cur:现在处理到哪一位。   s:搜索到目前为止,之前的状态,具体什么状态看情况而定。   e:是否到达边界,如果没到这一位只取到9,否则只能取到bit[cur]。   z:前导0标记,也就是是否前面的都是0,有些情况需要特殊判断。   一般情况

1386

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

uva11481 - Arrange the Numbers N个数前M个错排

Consider this sequence {1, 2, 3, … , N}, as a initial sequence of firstN natural numbers. You can rearrange this sequence in many ways. Therewill be N! different arrangements. You have to calculate t

1161

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

字符串DP

这几天在做DP,总结一下,先是字符串这一类的。   最简单的就是给你两个字符串a和b,让你求最长公共子序列(LCS)。用dp[i][j]作为第一个字符串匹配到i位置和第二个字符串匹配到j位置时的最长公共子序列,所以如果a[i]==b[j],dp[i][j]=dp[i-1][j-1]+1,否则dp[i][j]=max(dp[i-1][j],dp[i][j-1])。   之后一些题就和是这个的变形

1124

hdu5396 Expression 记忆化搜索+组合数 多校联合第九场

Expression Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 160    Accepted Submission(s): 90 Problem Description Teacher Mai has n nu

1085

uva12105 - Bigger is Better 大数

Bob has n matches. He wants to compose numbers using the following scheme (that is, digit 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 needs 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 matches): Fig 1 Digits from matches Write

1075

uva254 - Towers of Hanoi 递归

Towers of Hanoi  In 1883, Edouard Lucas invented, or perhaps reinvented, one of the most popular puzzles of all times - the Tower of Hanoi, as he called it - which is still used today in

990

hdu5262 最强密码 百度之星复赛 DP

最强密码 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 104    Accepted Submission(s): 62 Problem Description 由于近来密码库被盗的现象层出不穷,度度熊决定为自己的账

963

uva11600 - Masud Rana 状态压缩 期望

Masud Rana, A Daring Spy Of BangladeshCounter Intelligence. He is in a new mission. There is a total n cities in Bangladesh.Each city is connected to all other by bidirectional roads. So there are tot

921

uva10859 - Placing Lampposts 无根树转有根树 DP

As a part of the mission �Beautification of Dhaka City�, the government has decided to replace all the old lampposts with new expensive ones. Since the new ones are quite expensive and the budget is n

917

uva10154 - Weights and Measures

Problem F: Weights and Measures I know, up on top you are seeing great sights, But down at the bottom, we, too, should have rights. We turtles can't stand it. Our shells will all crack! Besides

912

uva12235 - Help Bubu 四维状态压缩DP

Bubu's bookshelf is in a mess! Help him! There are n books on his bookshelf. We define the mess value to be the number of segments of consecutive equal-height books. For example, if the book height

905

uva1427 - Parade 单调队列 维护递减数列

Panagola, The Lord of city F likes to parade very much. He always inspects his city in his car and enjoys the welcome of his citizens. City F has a regular road system. It looks like a matrix with n

836
上一篇: uva10900 - So you want to be a 2n-aire? 概率 递推
下一篇: 矩阵快速幂
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址