Optimal alpha beta pruning
Time limit2sMemory limit512 MB
Given a game tree with leaf values, find the minimum and maximum number of leaves alpha-beta pruning evaluates over all child orderings.
- Level
Medium7 of 10
- Topics
- Tree, Minimum spanning tree, Dynamic programming
- Solved
- No attempts yet
Problem
Fox Ciel is developing an artificial intelligence (AI) for a game. The game is described as a game tree with vertices. Each node has an evaluation value that shows how good a situation is. The value of a non-leaf node is the maximum of its children's values multiplied by . Leaf values are computed with Ciel's special function, which is heavy to evaluate. So Ciel uses alpha-beta pruning to compute the root's evaluation value while reducing the number of leaf nodes that are evaluated.
The order in which child nodes are evaluated changes how many leaf nodes are computed. Ciel wants the minimum and the maximum number of leaf evaluations she can get when she may evaluate the children of each node in any order. Ciel uses the following algorithm.
function negamax(node, α, β)
if node is a terminal node
return value of leaf node
else
foreach child of node
val := -negamax(child, -β, -α)
if val >= β
return val
if val > α
α := val
return α
Input
The first line contains an integer , the number of vertices in the game tree . The second line contains integers , the evaluation value of vertex . The next lines describe the tree. is the number of children of vertex , followed by the child indices .
n
p1 p2 ... pn
k1 t11 t12 ... t1k
:
:
kn tn1 tn2 ... tnk
- The root is vertex .
- The evaluation value of a non-leaf node is always in the input. You must compute it when needed.
- A leaf node may also have value .
- The game tree is a tree structure.
Output
Print the minimum and the maximum number of leaf evaluations, separated by a space.
minimum maximum