题目描述:

二维dp:

class Solution:
def probabilityOfHeads(self, prob: List[float], target: int) -> float:
dp = [[0 for _ in range(target+1)] for _ in range(len(prob)+1)]
dp[0][0] = 1.0
for i in range(1,len(prob)+1):
for j in range(target+1)[::-1]:
dp[i][j] = dp[i-1][j] * (1- prob[i-1])
if j > 0:
dp[i][j] += dp[i-1][j-1] * prob[i-1]
return dp[-1][-1]

一维dp:

class Solution:
def probabilityOfHeads(self, prob: List[float], target: int) -> float:
dp = [1] + [0] * target
for p in prob:
for i in range(target+1)[::-1]:
dp[i] = dp[i] * (1- p)
if i > 0:
dp[i] += dp[i-1] * p
return dp[-1]

leetcode-12周双周赛-5090-抛掷硬币的更多相关文章

  1. leetcode-第14周双周赛-1274-矩形内船只的数目

    题目描述: 自己的提交: # """ # This is Sea's API interface. # You should not implement it, or s ...

  2. leetcode-第14周双周赛-1273-删除树节点

    题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: Lis ...

  3. leetcode-第14周双周赛-1272-删除区间

    题目描述: 自己的提交: class Solution: def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[ ...

  4. leetcode-第14周双周赛-1271-十六进制魔术数字

    自己的提交: class Solution: def toHexspeak(self, num: str) -> str: num = hex(int(num)) num = str(num)[ ...

  5. leetcode-第12周双周赛-5111-分享巧克力

    题目描述: 方法: class Solution: def maximizeSweetness(self, A: List[int], K: int) -> int: def possible( ...

  6. leetcode-第10周双周赛-5099验证回文字符串③

    题目描述: 方法:动态规划 class Solution: def isValidPalindrome(self, s: str, k: int) -> bool: def isKPalRec( ...

  7. leetcode-第10周双周赛-5081-歩进数

    题目描述: 自己的提交:参考全排列 class Solution: def countSteppingNumbers(self, low: int, high: int) -> List[int ...

  8. leetcode-第10周双周赛-5080-查找两颗二叉搜索树之和

    题目描述: 自己的提交: class Solution: def twoSumBSTs(self, root1: TreeNode, root2: TreeNode, target: int) -&g ...

  9. leetcode-第10周双周赛-5079-三个有序数组的交集

    题目描述: 自己的提交: class Solution: def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: Li ...

随机推荐

  1. Python 基础 2-1 列表入门

    引言 列表 list 是由一系列按照特定顺序排列的元素组成的,它是一种有序的数据集合. 你可以添加任何类型的元素到列表中,其中的元素之间可以没有任何关系. 列表简介 Python 使用方括号 [] 来 ...

  2. nginx 和keepalived的使用

    今天看了培训视频,看到这俩玩意,挺有意思,先粘贴一下,别等到时候忘了. 官方网站 www.nginx.org nginx的特点 稳定版本是用偶数来做标记,测试版本使用奇数作为标记 通过yum来安装 安 ...

  3. redis集群添加新节点

    一.创建节点(接上文) 1.在H1服务器/root/soft目录下创建7002目录 2.将7001目录的配置文件redis.conf拷贝到7002,并修改配置文件的端口 3.进入 redis-5.0. ...

  4. vbs,修改文件名

    一次性能测试记录,因为项目要批量上传文件,奈何文件有50 * 2个,然后系统效验文件名,要不停地修改,找了一些资料整理脚本如下: strFolder = "\\xxxx\2018198_数据 ...

  5. Delphi中点击网页弹出的Alert对话框的确定按钮

    思路: 使用Windows API函数遍历窗口,查找指定标题的窗口,然后从该窗口查找确定按钮,向该按钮发送鼠标消息进行模拟点击.由于IE8由Alert弹出的网页对话框的标题是“来自网页的消息”,而IE ...

  6. jqery基础知识实例(二)

    无缝滚动 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  7. PHP ftp_alloc() 函数

    定义和用法 ftp_alloc() 函数为要上传到 FTP 服务器的文件分配空间. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 ftp_alloc(ftp_connectio ...

  8. Shiro学习(21)授予身份及切换身份

    在一些场景中,比如某个领导因为一些原因不能进行登录网站进行一些操作,他想把他网站上的工作委托给他的秘书,但是他不想把帐号/密码告诉他秘书,只是想把工作委托给他:此时和我们可以使用Shiro的RunAs ...

  9. JCF——Map

    Hashtable LinkedHashMap Properties

  10. delphi下运行vbscript脚本

    简单一个vb脚本,功能为打开被限制的注册表.Set wso = CreateObject("WScript.Shell")wso.RegWrite "HKEY_CURRE ...