//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.
Some results have been hidden because they may be inaccessible to you
Show inaccessible results