Click here to see the full article post
Check out my dfs solution in discussion, it's much faster :)
I think there is a minor typo, and correct me if I am wrong,
for this line:
for all j < i, f[i][A[i] - A[j]] += f[j][A[i] - A[j]],
it means that only when there is an arithmetic subsequence ending at A[j], then we could add that count to the new subsequence ending at A[i]. But it misses the case when the subsequence ending at A[j] is a weak one.