recursion and dp, 2d array rotation