cpp implementation of Unique Paths II