Simple knapscak using matrix to cache results