GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeetCode/DFS/638.Shopping-Offers at master · wisdompeak/LeetCode

Expand file tree

/

638.Shopping-Offers

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

638.Shopping-Offers

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
638.Shopping-Offers.cpp
638.Shopping-Offers.cpp
 
 
638.Shopping-Offers.py
638.Shopping-Offers.py
 
 
638.Shopping-Offers_v2.cpp
638.Shopping-Offers_v2.cpp
 
 
638.Shopping-Offers_v3.cpp
638.Shopping-Offers_v3.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

638.Shopping-Offers

设计递归函数dfs(state),其中state表示还有哪些物品没有采购,返回的值表示采购完这些物品的最少代价。

考虑到最多只有6件物品,每个物品最多6个。所以我们用18个bit的二进制数来表示状态。每3个bit可以表示该种物品的数量(从0到7)。

在dfs(state)里,为我们尝试每一种合法的offer,将state更新后递归处理。我们取所有尝试中代价最小的结果,并记录在memo[state]里面。

需要注意的细节:

  1. 有些offer是不合算的,可以提前从special里排除掉;
  2. 在dfs(state)里,除了尝试offer,还可以直接从prices里面按原价采购每一件物品。

PS: 最新的题目里把每种物品的数量放宽到了10件,所以需要4*6=24个bit的二进制数来表示状态。

Leetcode Link

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.