Simple medium-level DP solution
IntuitionAt first glance, it seems like a hard question because at each index i, we need to check for all possible absolute differences against all pairs of pri
### Intuition
At first glance, it seems like a hard question because at each index i, we need to check for all possible absolute differences against all pairs of prior values.

How about creating a directed graph with edges e = {i,j,v}, such that i and j are indices, i<j, edge's direction is from i to j, and edge's weight **v** is abs(nums[i]-nums[j])? We can then try to find the longest path in this graph, such that among the path, **v** between each adjacent nodes must be non-increasing.

However, the starting point cannot be fixed. It is impossible to determine the best starting point such that the longest path must be found with that starting point. If you try to find the longest path while trying all possible starting points, you will get time limit exceeded.

Therefore, here is one working solution:

* For each value at position (i), and for each possible absolute difference value (d) (in this question, it is only in the range of [0,299]), there are only two possible prior values: nums[i]-d, nums[i]+d. Let this value be (p)
* For each of those (p) values, check if the value is within range of values among the array nums. 
* If it is valid, then check this: **The max subsequence length which ends at the latest ending position k such that nums[k]=(p), and the absolute difference between (p) and any one (p)'s prior value is >= d (non-increasing abs difference subsequence)**
* Create the 2D array D, such that the dimensions represent: D[the ending position][the abs difference value], and the value is max length with abs difference >= d.
* After updating the records, perform a scan from largest possible absolute difference (maxD) to the smallest (minD). 
* For each difference value (curD), update D[i][(curD)] with max(D[i][(curD+1...maxD)])

It is, actually, just a regular medium level question after all. But, I am not saying that it is a direct implementation of any existing copy-pastable template code.

It is just a fun question anyways. 

### Approach
<!-- Describe your approach to solving the problem. -->
Implement the idea mentioned directly using code. 
### Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
~O(n*600)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
~O(n*300) anyways.

### Code
```cpp []
class Solution {
public:
    const static int MAX=1e4+4;
    const static int MAXV=304;
    int D[MAX][MAXV]; int I[MAXV];
    int longestSubsequence(vector<int>& nums) {
        memset(D,0,sizeof(D));
        for (int i=0; i<MAXV; i++) {D[0][i]=1;}
        memset(I,-1,sizeof(I)); I[nums[0]]=0;
        int len=nums.size(); int tar,tmp;
        int res=1;
        for (int i=1; i<len; i++) {
            for (int d=0; d<MAXV; d++) {
                for (int f=-1; f<=1; f+=2) {
                    tar=f*d+nums[i];
                    if (tar>=0&&tar<MAXV) {
                        if (I[tar]!=-1) {
                            D[i][d]=std::max(D[i][d],D[I[tar]][d]+1);
                        }
                    }
                }
            }
            tmp=std::max(1,D[i][MAXV-1]);
            int pi=I[nums[i]];
            for (int j=MAXV-1; j>=0; j--) {
                tmp=std::max(D[i][j],tmp);
                if (pi!=-1) {tmp=std::max(D[pi][j],tmp);}
                D[i][j]=tmp;
                res=std::max(res,tmp);
            }
            I[nums[i]]=i;
            D[i][0]=std::max(D[i][0],1);
        }
        return res;
    }
};




```
['C++']