Why does adding DP to my recursion make it stop working correctly

welcome to shbcf.ru