DP solution||Using hint
Use the hint: Store the maximum answer for each index and every possible difference.
Store dp[i][j] as max(dp[i][0 ... j])
Update dp in the reverse way
Store th
Use the `hint`: Store the maximum answer for each index and every possible difference.
Store `dp[i][j]` as `max(dp[i][0 ... j])`
Update `dp` in the reverse way
Store the result as max of the already calculated part

# Code
```cpp []
#include <ranges>

class Solution {
    constexpr static int max_num = 300;
public:
    int longestSubsequence(vector<int>& nums) {
        vector<vector<int>> dp(max_num + 2, vector<int>(max_num + 2));

        ranges::for_each(nums | views::reverse, [&dp](int num) {
            for (int i = 1; i <= max_num; ++i) {
                const auto diff = abs(i - num);
                dp[num][diff] = max(dp[num][diff], dp[i][diff] + 1);
            }

            ranges::for_each(views::iota(1, max_num + 1), [&dp, num](int i) {
                dp[num][i] = max(dp[num][i], dp[num][i - 1]);
            });
        });

        return ranges::max(dp | views::join);
    }
};
```
['C++']