当前位置:网站首页>Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
2022-07-03 22:16:00 【White speed Dragon King's review】


Ideas :
1. Use bit operation to compress the state of basket vacancy
2. Use dp, To represent in a given state , front i Maximum and sum of
src:
class Solution:
def maximumANDSum(self, nums: List[int], numSlots: int) -> int:
# f(i, mask) Show consideration nums In front of i It's an integer , Basket availability status is mask
@lru_cache(None)
def f(i, mask):
if i < 0:
return 0
t, w, res = mask, 1, 0
# Traverse the basket
for k in range(1, numSlots + 1):
# Ruodi k Baskets are still available
if t % 3:
# Choose him , And the previous results
res = max(res, f(i - 1, mask - w) + (k & nums[i]))
# Consider the next basket
t, w = t // 3, w * 3
return res
return f(len(nums) - 1, 3 ** numSlots - 1)
summary :
[email protected]_cache Memory search
2. use n Binary to compress the state (n States )
3. Traverse all possible , Take out the biggest
边栏推荐
- 1068. Consolidation of ring stones (ring, interval DP)
- [actual combat record] record the whole process of the server being attacked (redis vulnerability)
- 十大券商开户注册安全靠谱吗?有没有风险的?
- The 14th five year plan and investment feasibility study report of China's industry university research cooperation Ⓧ 2022 ~ 2028
- Pooling idea: string constant pool, thread pool, database connection pool
- Minio deployment
- Collections SQL communes
- Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
- Leetcode problem solving - 235 Nearest common ancestor of binary search tree
- Base ring tree Cartesian tree
猜你喜欢

4 environment construction -standalone ha

BUUCTF,Misc:LSB

Data consistency between redis and database

Blue Bridge Cup Guoxin Changtian MCU -- program download (III)

Common SQL sets
![[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list](/img/db/b992d2b461ca17652518a1511b4947.gif)
[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list

Electronic tube: Literature Research on basic characteristics of 6j1

Go Technology Daily (2022-02-13) - Summary of experience in database storage selection

2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units

Summary of basic knowledge of exception handling
随机推荐
JS closure knowledge points essence
Codeforces Round #768 (Div. 1)(A-C)
regular expression
Base ring tree Cartesian tree
Pooling idea: string constant pool, thread pool, database connection pool
Nacos common configuration
DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD
Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
Sed、Awk
Why should enterprises do more application activities?
Mindmanager2022 serial number key decompression installer tutorial
How does sentinel, a traffic management artifact, make it easy for business parties to access?
A little understanding of GSLB (global server load balance) technology
WiFi 2.4g/5g/6g channel distribution
DR-NAS26-Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-5GHz-high-power-Mini-PCIe-Wi-Fi-Module
4 environment construction -standalone ha
Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
Is it safe and reliable to open an account and register for stock speculation? Is there any risk?
Teach you how to install aidlux (1 installation)
Yyds dry goods inventory hands-on teach you to create a jigsaw puzzle using the canvasapi