Problem Statement
题目简述
以网格图的形式给出一个无根树,
以及树的点集的一个子集 C。
现从 C 的所有大小为 K 的子集中等概率选取一个子集 S,
记 length 为树中经过所有 S 中的点的最短路径长度
(路径长度定义为经过的边数,可以重复经过同一条边,此时长度需要被计算多次)。
给定无根树、点集 C 以及整数 K,求 length 的期望值。
树的节点数不超过 50*50,c<=300,2<=K<=|C|。
Mrs. Jeipouju is planning to practice orienteering.
The area where she'll practice is a rectangular field divided into unit squares.
You are given its description as a String[] field.
Each character in field is '.' (a period), '*' (an asterisk), or '#' (a number sign).
Each '.' represents a passable square without a checkpoint, each '*' represents a passable square with a checkpoint, and each '#' represents an impassable obstacle.
It is guaranteed that all passable squares (i.e., all '.'s and '*'s) form a 4-connected tree (see notes for formal definition).
The number of checkpoints is at most 300.
In order to practice, Mrs. Jeipouju chooses K of the checkpoints uniformly at random.
Afterwards, she will find the shortest sequence of squares that passes through all chosen checkpoints.
The sequence can start at any square, end at any square (possibly other than the starting one), and visit each square any number of times.
Each pair of consecutive squares in the sequence must have a common side.
The length of the sequence is the number of moves Mrs. Jeipouju will have to make.
(So, for example, a sequence that consists of 7 squares has length 6.)
You are given the String[] field and the int K.
Return the expected length of Mrs. Jeipouju's sequence.