Dynamic programming problem help

Revision en1, by typedeftemplate, 2020-05-19 20:33:11

Hi everyone,

I am pretty new to dynamic programming, and I have been struggling with the following problem:

Given an array of integers, how can I find the longest contiguous arithmetic subsequence? For instance, if our entries are 10, 3, 5, 7, 9, 11, 5, 8, 7, 13, 14, then I would have to return "5" since 3, 5, 7, 9, 11 forms the longest contiguous arithmetic subsequence.

I thought about defining dp[i][j] to be the longest contiguous arithmetic subsequence ending at index i with common difference equal to j, but I can't really come up with the transitions properly.

I would really appreciate it if someone could please help me with this problem.

Tags #dp, #dynamic programing, dp

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English typedeftemplate 2020-05-19 20:33:11 697 Initial revision (published)