3
* dp[i][j] is the max length of fibbonacci series whose last two elements5
* for any integer A[k] we need to find two number A[i] & A[j] such that6
* i < j < k and A[i] + A[j] == A[k], we can find such pairs in O(n) time8
* if there exist i,j,k such that i < j < k and A[i] + A[j] == A[k] then9
* dp[k][j] = dp[i][j] + 1 (A[k], A[j] are last two elements of fibbonacc series)11
public int lenLongestFibSubseq(int[] A) {13
int[][] dp = new int[n][n];15
for (int k = 2; k < n; k++) {18
int sum = A[i] + A[j] - A[k];24
// ith, jth kth element are fibbonaci sequence25
dp[j][k] = dp[i][j] + 1; // since numbers are unique26
result = Math.max(result, dp[j][k]);32
return result + 2 >= 3 ? result + 2 : 0;