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/Dynamic_Programming/656.Coin-Path at master · wisdompeak/LeetCode

Expand file tree

/

656.Coin-Path

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

656.Coin-Path

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
656.Coin-Path.cpp
656.Coin-Path.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

656.Coin-Path

如果仅是输出最优路径,那么就是一道简单的DP题。本题的特殊性在于要求 the lexicographically smallest path

如果从正向考虑,考察dp[i]时,必须考察从 i-B 到 i-1 之间的元素,如果有若干并列的最小权重路径,该如何取舍呢?比如dp[x]和dp[y]都符合要求,且x<y,那么选择x吗?显然不行,因为从0行进到x的路径,可能就比从0行进到y的路径,在字典序上更大。反之,选择y也没有道理。

怎么解决呢?最巧妙的方法是,从反向考虑,考察从N-1行进到0的最优路径。

比如,考察dp[i]时,必须考察从 i+1 到 i+B 之间的元素,如果有若干并列的最小权重路径,该如何取舍呢?比如dp[x]和dp[y]都符合要求,且x<y,那么我们就要选择x。因为从0到i到x到N-1的路径,肯定要比从0到i到y到N-1的路径在字典序上更小。

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.