Skip to content

Commit

Permalink
Update Readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Oct 3, 2021
1 parent 9986e53 commit 3fd24ad
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Recursion/679.24-Game/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

我们遍历这个四个数字的permutaion。对于任意一种permuation ```A B C D```,我们本质上需要做的就是任意添加运算符(加减乘除)和括号(改变运算顺序),查看整个式子eval的结果是否包含24.

具体的做法就是递归。我们将某个permutation拆解为两部分分别递归处理,再将每个部分eval出来的结果两两组合,配上加减乘除,就得到对于这个permutation我们所能计算出的所有可能值。
具体的做法就是递归。我们将某个permutation拆解为两部分分别递归处理,再将两个部分eval出来的结果两两组合,配上加减乘除,就得到对于这个permutation我们所能计算出的所有可能值。大致的代码是
```
for x: eval(AB)
for y: eval(CD)
rets.insert({x+y, x-y, x*y, x/y});
```

需要注意,所有的牌必须处理成浮点,因为涉及到除法。

Expand Down

0 comments on commit 3fd24ad

Please sign in to comment.