leetcode-12周双周赛-5090-抛掷硬币
题目描述:

二维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-抛掷硬币的更多相关文章
- leetcode-第14周双周赛-1274-矩形内船只的数目
题目描述: 自己的提交: # """ # This is Sea's API interface. # You should not implement it, or s ...
- leetcode-第14周双周赛-1273-删除树节点
题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: Lis ...
- leetcode-第14周双周赛-1272-删除区间
题目描述: 自己的提交: class Solution: def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[ ...
- leetcode-第14周双周赛-1271-十六进制魔术数字
自己的提交: class Solution: def toHexspeak(self, num: str) -> str: num = hex(int(num)) num = str(num)[ ...
- leetcode-第12周双周赛-5111-分享巧克力
题目描述: 方法: class Solution: def maximizeSweetness(self, A: List[int], K: int) -> int: def possible( ...
- leetcode-第10周双周赛-5099验证回文字符串③
题目描述: 方法:动态规划 class Solution: def isValidPalindrome(self, s: str, k: int) -> bool: def isKPalRec( ...
- leetcode-第10周双周赛-5081-歩进数
题目描述: 自己的提交:参考全排列 class Solution: def countSteppingNumbers(self, low: int, high: int) -> List[int ...
- leetcode-第10周双周赛-5080-查找两颗二叉搜索树之和
题目描述: 自己的提交: class Solution: def twoSumBSTs(self, root1: TreeNode, root2: TreeNode, target: int) -&g ...
- leetcode-第10周双周赛-5079-三个有序数组的交集
题目描述: 自己的提交: class Solution: def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: Li ...
随机推荐
- pickle模块 和json模块
pickle和json序列号 json模块是所有语言通用的,可以用来把一些数据转成字符串存储在文件中 import json l=[,,] with open('t3',mode='w',encodi ...
- 使用ReadStream方法延时读取文件
const fs = require('fs'); let file = fs.createReadStream("filenpath.js"); file.pause(); fi ...
- 前端学习(一)html标签(笔记)
html->标签 标题标签:<h1>标题文字</h1>段落标签:<p>段落文字</p>换行标签:<br/>图片标签:<img s ...
- Async Clipboard AP
转自奇舞周刊,个人学习记录,侵权删 编者按:本文作者李松峰,资深技术图书译者,翻译出版过40余部技术及交互设计专著,现任360奇舞团高级前端开发工程师,360前端技术委员会委员.W3C AC代表 如果 ...
- spring 转换器和格式化
Spring总是试图用默认的语言区域将日期输入绑定 到java.util.Date.假如想让Spring使用不同的日期样 式,就需要用一个Converter(转换器)或者 Formatter(格式化) ...
- Service5
DHCP概述及原理• Dynamic Host Configuration Protocol – 动态主机配置协议,由 IETF(Internet 网络工程师任务小组)组织制定,用来简化主机地址分配 ...
- artTemplate性能卓越的 js 模板引擎
artTemplate-3.0 新一代 javascript 模板引擎 目录 特性 快速上手 模板语法 下载 方法 NodeJS 使用预编译 更新日志 授权协议 特性 性能卓越,执行速度通常是 Mus ...
- jeecg 实现lhgDialog窗口传值
需要在jeecg中的dialog弹框往调用的窗口赋值. 定义内容页调用窗体实例对象接口 var windowapi = frameElement.api ; var W = windowapi.ope ...
- C++——类
1.类和结构体,只有的默认访问权限的区别 2.类内不能定义和类外类型名相同的类型名.为什么?typedef机制? typedef double money; class Account { priva ...
- 剑指offer第二版面试题8:用两个栈实现队列(JAVA版)
题目:用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail和deletedHead,分别完成在队列尾部插入节点和在队列头部删除节点的功能. 分析: 我们通过一个具体的例子来分析 ...