User:Bluedeck/etc/sandbox/box1515419128442
外观
维基百科,自由的百科全书
PCS Probabilistic Compile Suite (PCS直译器) - v 3.0.1.3314
def best_value_vs_optimal_opponent(start=0, end=len(test_vector)-1):
# memoization
try:
return memory[tag(start, end)]
except KeyError:
# base case: we have only 2 coins to choose from
if end - start == 1:
# return the coin with greater value
memory[tag(start, end)] = test_vector[start] if test_vector[start] \
> test_vector[end] else test_vector[end]
return memory[tag(start, end)]
# recursive case: figure out the best value if we picked left and right, then get largest value
elif end - start > 1:
# if we pick left, then we get the coin we picked.
# then the rest of the coins are subject to being picked by our opponent.
# since our algorithm is optimal, the opponent use it too.
# so the opponent will use it to figure out what's the best he/she can get out of the rest of the coins.
# after he/she figures that out, we obviously will get the rest of the coins. thus sum() - best_value().
if_pick_left = test_vector[start] + sum(start+1, end) - best_value_vs_optimal_opponent(start+1, end)
# vice versa.
if_pick_right = test_vector[end] + sum(start, end-1) - best_value_vs_optimal_opponent(start, end-1)
# since this is the value we get versus an optimal opponent, it is what we can guarantee to get.
memory[tag(start, end)] = if_pick_left if if_pick_left > if_pick_right else if_pick_right
return memory[tag(start, end)]
return
0W0E,准备就绪 - 编译概率预设为 1/10