当前位置:网站首页>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
边栏推荐
- How to store null value on the disk of yyds dry inventory?
- Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
- IPhone development swift foundation 09 assets
- [SRS] build a specified version of SRS
- gslb(global server load balance)技術的一點理解
- Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
- Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
- [secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]
- Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming
- Remember the experience of automatically jumping to spinach station when the home page was tampered with
猜你喜欢

Compréhension de la technologie gslb (Global Server load balance)

Imitation Netease cloud music applet

Control loop of program (while loop)

Mysql database - Advanced SQL statement (I)

Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)

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

STM32 multi serial port implementation of printf -- Based on cubemx

Collection | pytoch common loss function disassembly

Covariance

Redis single thread and multi thread
随机推荐
[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
Nacos common configuration
Persistence of Nacos
How PHP drives mongodb
2022 electrician (elementary) examination questions and electrician (elementary) registration examination
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
js demo 计算本年度还剩下多少天
3 environment construction -standalone
1 Introduction to spark Foundation
Awk getting started to proficient series - awk quick start
[Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
js demo 計算本年度還剩下多少天
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Collection | pytoch common loss function disassembly
The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)
Cesium terrain clipping draw polygon clipping
Common problems in multi-threaded learning (I) ArrayList under high concurrency and weird hasmap under concurrency