dp array length is n