题目描述:

二维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. JNI intArray

    JNIDemo.java public class JNIDemo { static { /* 1. load */ System.loadLibrary("native"); / ...

  2. Java 简单链表实现

    1.初衷 最近在看Java基础,有一章节涉及到链表,便记之所学所得. 2.链表的定义 链表是存储地址不连续的线性存储结构 3.链表的基本结构 一个节点包含当前节点,与下个节点的引用 4.简单链表的实现 ...

  3. 微信小程序分享功能的path路径

    表示被微信小程序坑惨了 糟心的开始写,老板说先不上太复杂,就先显示了两个页面,然后开开心心的发布,测试了几遍,没啥问题呀.结果,一上上去,就被老板批了! 啥呀! 这分享怎么这个鬼样子!明明我看文档都是 ...

  4. vue 学习七 组件上使用插槽

    我们有时候可能会在组件上添加元素,就像下面那样 <template> <div id="a"> <com1> <p>我是渲染的值&l ...

  5. fiddler增加ip以及响应时间列

    最近打算看一下移动端app的响应等请求,这里打算用fillder来查看appium的模拟出发请求的操作来查看结果, 所以我们需要在左侧的面板增加我们所需要的ip,响应时间等数据以方便我们查看 fidd ...

  6. leetcode-160周赛-5239-循环码排列

    题目描述: 参考格雷编码: class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: res ...

  7. git ,报403错误,完美解决方案

    首先命令行操作结果如下: root@zhiren-PowerEdge-T110-II:/zrun# git clone https://git.coding.net/xxxxxxxx/xxxx.git ...

  8. 「FJOI2018」领导集团问题 解题报告

    「FJOI2018」领导集团问题 题意:给你一颗\(n\)个点的带点权有根树,选择一个点集\(S\),使得点集中所有祖先的点权$\le \(子孙的点权,最大化\)|S|$(出题人语死早...) 一个显 ...

  9. centos 安装 ImageMagick

    ImageMagick很好用,shell下可以批量对图片做处理,很赞!~ 编译安装 wget http://www.imagemagick.org/download/ImageMagick.tar.g ...

  10. [SDOI2015]排序 题解 (搜索)

    Description 小A有一个1-2^N的排列A[1..2^N],他希望将A数组从小到大排序,小A可以执行的操作有N种,每种操作最多可以执行一次,对于所有的i(1<=i<=N),第i中 ...