classic dp and recursive