C++ Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n    Similar to Coin Change Problem\n\n# Approach\n Describe your approach to solving th
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n    Similar to Coin Change Problem\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n    Recursive DP\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(N * N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(N * N)\n\n# Code\n```\n#define inf 1000000009\nclass Solution {\npublic:\n    vector<int> num;\n    int dp[1005][1005];\n    int solve(int i, int target)\n    {\n        if(target < 0) return -inf;\n        if(i > num.size() - 1) {\n            if (target == 0) return 0;\n            else return -inf;\n        }\n        if(dp[i][target] != -1) return dp[i][target];\n        int ret1 = 1 + solve(i + 1, target - num[i]);\n        int ret2 = solve(i + 1, target);\n        return dp[i][target] = max(ret1, ret2);\n    }\n\n    int lengthOfLongestSubsequence(vector<int>& nums, int target) {\n        num = nums;\n        memset(dp, -1, sizeof dp);\n        int ans = solve(0, target);\n        if(ans < 0) return -1;\n        return ans;\n    }\n};\n```
['C++']