464. Can I Win
题目描述
In the “100 game,” two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins.
What if we change the game so that players cannot re-use integers?
For example, two players might take turns drawing from a common pool of numbers of 1..15 without replacement until they reach a total >= 100.
Given an integer maxChoosableInteger and another integer desiredTotal, determine if the first player to move can force a win, assuming both players play optimally.
You can always assume that maxChoosableInteger will not be larger than 20 and desiredTotal will not be larger than 300.
Example
|
|
题目大意
提供两个整数 maxChoosableInteger
和 desiredTotal
两个玩家轮流从 1~maxChoosableInteger
,直到 总和 >= desiredTotal
,确定第一个玩家是否能获胜。 1~maxChoosableInteger
不能重复选择。
解题思路
通过
visited
数组记录是否数字是否已经被访问过。map
记录当前组合是否被访问过。
简单粗暴的DFS
。
代码
|
|