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 ...
随机推荐
- Centos7上MariaDB数据库启动问题解决
安装MariaDB数据库后出现服务启动失败问题, 解决办法:卸载再安装!(确定无3306端口占用) 一.卸载数据库: [root@localhost logs]# yum -y remove mari ...
- Django之Form操作
一.Form基础 (一)Form的作用 Django的Form主要有以下几大作用: 生成HTML标签 验证用户数据(显示错误信息) Form提交保留上次提交数据 初始化页面显示数据 (二)实例 一般网 ...
- 转译es6原生原生对象及方法,如Object.assign,Object.keys等,及promise
下面主要为兼容恶心的ie 1,首先引入‘babel-polyfill’,可写在webpack.dev.js的entry.vendors数组里面 2,在入口文件如app.js里面import 'babe ...
- mysql的数据导出方法2
首先,使用mysqldump命令的前提是,在Cmd中进入mysql安装目录下的bin目录下,才可以使用该命令.我的mysql安装在E:盘,所以,首先进入bin目录下:E:/Program Files/ ...
- spring.xml及注解
spring.xml配置文件中配置注解: 开启注解(及自动扫描包中bean): 1:<context:component-scan base-package="com.bzu" ...
- Dart编程实例 - 类型测试操作符 is!
Dart编程实例 - 类型测试操作符 is! void main() { double n = 2.20; var num = n is! int; print(num); } 本文转自:http:/ ...
- thinkphp SAE
SAE介绍 Sina App Engine(简称SAE)是新浪研发中心开发的国内首个公有云计算平台,是新浪云计算战略的核心组成部分,作为一个简单高效的分布式Web服务开发.运行平台越来越受开发者青睐. ...
- linux IPC socket
套接字是通讯端点的抽象 创建一个套接字 #include <sys/types.h> #include <sys/socket.h> int socket(int domain ...
- CCC2018 最大战略储备
并查集基本处理即可. #include <cstdio> #include <iostream> #include <algorithm> #include < ...
- 20165239 2018——2019Exp8 Web基础
Exp8 Web基础 基础问题回答 (1)什么是表单 •表单在网页中主要负责数据采集功能. •一个表单有三个基本组成部分: ◦表单标签,这里面包含了处理表单数据所用CGI程序的URL以及数据提交到服务 ...