Implemented dp and res