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 ...
随机推荐
- codeforces 1198E Rectangle Painting 2 最小点覆盖
题目传送门 题意: 有一个$n∗n$的网格,网格中有一些矩形是黑的,其他点都是白的. 你每次可以花费$ min (h,w)$的代价把一个$h*w$的矩形区域变白.求把所有黑格变白的最小代价. 思路: ...
- PHP-最长有效括号
给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度. 示例 1: 输入: "(()"输出: 2解释: 最长有效括号子串为 "()" ...
- div::before一个能插入元素的选择器
div::before一个能插入元素的选择器
- 70. SequenceInputStream(文件合并)
缓冲输入字节流:----------------------| InputStream 输入字节流的基类----------------| FileInputStream 读取文件的输入字节流--- ...
- Java中的时间日期Date和Calendar
日期时间类 Date: Date类的构造方法: 可以发现Date类的toString方法被重写了. Date类的方法: SimpleDateFormat 它提供了解决Date输出问题的解决方案--格式 ...
- Mysql学习笔记(002)-基础查询
基础查询 # 进阶1:基础查询 /* 语法: select 查询列表 from 表名: 类似于:system.out.println(打印东西); 特点: 1.查询列表可以是:表中的字段,常量值,表达 ...
- H5新属性 contenteditable
contenteditable 属性规定元素内容是否可编辑 <div contenteditable style="width: 100px;height:100px"> ...
- 分享linux中导入sql文件的方法
为使用阿里云主机,没有装ftp,也没有装phpmyadmin,所以一切都得靠命令行.转移网站的重要一步就是转移数据库,这里简单介绍一下如何在这种情况下导入sql文件 因导出sql文件 在你原来的网站服 ...
- 【TCP/IP】TCP的三次握手和四次挥手
传输控制协议(TCP)是一种面向连接的协议,网络程序使用这个协议的时候,网络可以保证客户端和服务端的连接是可靠的,安全的. 如果 A机向 B机发送“hello”,在物理网线上传输的数据不仅仅是“hel ...
- Github上发布托管和下载
打包托管 远程下载安装 git clone https://github/2008nmj/mnist_python 使用git工具和命令行 Git使用场景 (可以不用上传到托管平台) 写论文 分工合作 ...