//There is definitely a way to do this with DP but you need to change the recursive approach a bit. //I think it's worth optimizing and solving if you can.