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/1690.Stone-Game-VII at master · black128/LeetCode

Expand file tree

/

1690.Stone-Game-VII

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

1690.Stone-Game-VII

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
1690.Stone-Game-VII.cpp
1690.Stone-Game-VII.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

1690.Stone-Game-VII

本题和1563.Stone-Game-V类似,典型的区间型DP。令dp[i][j]表示我方在先手处理[i:j]时可以得到的最多的、领先对手的分差。注意,这里的分差是相对于对手在这个区间内的得分而言。

我方在处理[i:j]区间时就两种选择。

第一种是我方选择第i个元素。这样我方在本轮得分sum[i+1:j],之后的局势是对方处理[i+1:j],从递归的角度来看,对手可以在此区间内领先我方的最大分差是dp[i+1][j]。所以回溯到本轮,我方先手处理[i:j]区间能够得到的最大分差就是sum[i+1:j]-dp[i+1:j].

第二种是我方选择第j个元素,同理我方可以得到的最大分差就是sum[i:j-1]-dp[i:j-1]。

综上,我方会在上面两种方案中选择更优的一种。

最后答案的输出就是dp[1:n].

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.