Please don't use dp. will cause memory limit exceeded


#1

If you store your result for faster access, it won’t accept. just brute force it.