You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #142 on September 15, 2026 11:12.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/stone-game-ii/
Problem Summary
돌들이 있고 Alice와 Bob이 차례로 돌을 가져갈 때 최대가 되게 가져가는 점수를 구하는 문제.
1 - 2*M개의 돌을 가져갈 수 있다.
Solution
이런 게임류 문제가 익숙하지 않으면 꽤 어렵다.
이렇게 두면 좀 보일까 싶은데 쉽지 않다.
여기서 Alice와 Bob의 관계를 생각해봐야 하는데 Alice는 Bob이 최소로 가져가게 골라야 한다.
그럼 Alice가 가져가는 양은? i부터 n까지의 전체 합에서 Bob이 가져가는 양을 뺀 만큼을 가져가게 된다.
i부터 n까지의 합을 구하기 위해서는 prefix sum / suffix sum을 써서 한번에 구하면 된다.
Source Code
All reactions