当前位置:网站首页>Leetcode: question d'entrevue 08.13. Empiler la boîte [DFS en haut + mémoire ou tri en bas + DP]
Leetcode: question d'entrevue 08.13. Empiler la boîte [DFS en haut + mémoire ou tri en bas + DP]
2022-06-23 16:24:00 【Rétrospective du roi dragon blanc】

Analyse
Ce sujet de sélection d'éléments sur demande a souvent deux idées
De haut en bas.dfs + memory Très élégant.
Et l'ordre du bas vers le haut + dp Et élégant
dfs + memory
class Solution:
def pileBox(self, box: List[List[int]]) -> int:
# sol(w, d, h) => if we choose(w, d, h), what's our maxHeight
@cache
def dfs(w, d, h):
choices = [(nw, nd, nh) for nw, nd, nh in box if nw < w and nd < d and nh < h]
if not choices: return h # we can not dfs
return h + max([dfs(nw, nd, nh) for nw, nd, nh in choices]) # dfs
# outer entry
return max([dfs(w, d, h) for w, d, h in box])
sort + dp
class Solution:
def pileBox(self, box: List[List[int]]) -> int:
box.sort()
n = len(box)
# dp[i] => box[i] as bottom maxHeight
dp = [box[i][2] for i in range(n)]
# Variation de la séquence ascendante la plus longue
for i in range(n):
for j in range(i):
# check all j before i
if box[j][0] < box[i][0] and box[j][1] < box[i][1] and box[j][2] < box[i][2]:
# if i can add after j
dp[i] = max(dp[i], dp[j] + box[i][2])
#print(i, dp[i])
#print(dp)
return max(dp)
Résumé
Sélectionner les questions
dfs or dp
L'élégance n'est jamais démodée
边栏推荐
- PageHelper在面对复杂service数据处理下的分页问题
- Thinking analysis of binary search method
- How is it cheaper to open a stock account? Is it safe to open an account online now?
- Log4j log integration and configuration details
- Build vscode into an invincible IDE (14) tasks JSON and launch JSON configuration details, add automation tasks at will
- 【OpenHarmony】usb gadget 配置hdc功能cfg文件解读
- Matlab: how to know from some data which data are added to get a known number
- Detailed explanation of MQ message oriented middleware theory
- get_ edges
- 创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
猜你喜欢
![Generating binary search balanced tree [using tree recursion]](/img/b3/f8edf45bdfdced7c3698088dbf7d84.png)
Generating binary search balanced tree [using tree recursion]

PageHelper faces the paging problem of complex service data processing

【历史上的今天】6 月 23 日:图灵诞生日;互联网奠基人出生;Reddit 上线

Block, non block, multiplexing, synchronous, asynchronous, bio, NiO, AIO

get_ edges

科大讯飞神经影像疾病预测方案!

【TcaplusDB知识库】Tmonitor系统升级介绍

如何让销售管理更高效?

SaaS cloud tool, a sharp tool for change under the industrial Internet

openGauss数据库源码解析系列文章—— 密态等值查询技术详解(上)
随机推荐
企业想上MES系统?还得满足这些条件
golang数据类型图
Tips for accelerating file transfer between windows remote desktop connections
golang冒泡排序代码实现
How is it cheaper to open a stock account? Is it safe to open an account online now?
How can I get the discount for opening a securities account? Is online account opening safe?
A tour of grpc:01 - Basic Theory
TCP protocol notes
总结一下购买阿里云服务器的经验
股票开户如何便宜一些?现在网上开户安全么?
腾讯的技术牛人们,是如何完成全面上云这件事儿的?
[tcapulusdb knowledge base] Introduction to new models of tcapulusdb
js中 if 直接判断 数据类型 结果举例
Pytorch: saving and exporting models
聚焦:ZK-SNARK 技术
ADB 按键名、按键代码数字、按键说明对照表
Readimg: read picture to variable variable variable
R语言使用magick包的image_scale函数对图像进行缩放(resize)、可以自定义从宽度或者高度角度进行缩放
Block, non block, multiplexing, synchronous, asynchronous, bio, NiO, AIO
Generating binary search balanced tree [using tree recursion]