Checker Moves on a Cube Surface
Шашка на кубі
Statement
A cube's surface is divided, by lines parallel to its edges, into square
cells whose side is 1/l of the cube's edge length (l an odd natural
number). A checker moves, one move at a time, to a cell orthogonally
adjacent to its current one (sharing a full side). Write draught.* to
compute the number of distinct m-move paths the checker can take from the
cell at the center of one face to the cell at the center of an adjacent
face.
Input / Output
File draught.dat holds natural numbers l and m (l < 52, m < 200).
File draught.res holds the number of distinct paths.
Constraints
l < 52m < 200
Example
l = 3, m = 3 gives 1 path.
Solution idea
Treat the cube's surface grid cells as nodes of a graph, with edges between
orthogonally adjacent cells — including across the folds between adjacent
faces — and count walks of length m between the two fixed start and end
cells by dynamic programming: propagate a "number of ways to be here after
i moves" count over all 6l² cells for i = 1..m. Since l < 52 the
whole surface has under roughly 16000 cells, so an O(m × l²) DP comfortably
fits the given bounds.