Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
soup-servings.py 794 Bytes
Copy Edit Raw Blame History
Allen Liu authored 2018-10-12 01:33 +08:00 . remove sensitive question description
# Time: O(1)
# Space: O(1)
class Solution(object):
def soupServings(self, N):
"""
:type N: int
:rtype: float
"""
def dp(a, b, lookup):
if (a, b) in lookup:
return lookup[a, b]
if a <= 0 and b <= 0:
return 0.5
if a <= 0:
return 1.0
if b <= 0:
return 0.0
lookup[a, b] = 0.25 * (dp(a-4, b, lookup) +
dp(a-3, b-1, lookup) +
dp(a-2, b-2, lookup) +
dp(a-1, b-3, lookup))
return lookup[a, b]
if N >= 4800:
return 1.0
lookup = {}
N = (N+24)//25
return dp(N, N, lookup)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search