dynamic programming on tree graphs in discrete time and space with dense transition matrices