C++ 1-D dp easy to understand, beats 99%
Complexity\n- Time complexity: O(target * n)\n\n- Space complexity: O(1001)\nmore optimal space complexity can be O(max(target, max value from nums))\n\n# Code\
# Complexity\n- Time complexity: O(target * n)\n\n- Space complexity: O(1001)\nmore optimal space complexity can be O(max(target, max value from nums))\n\n# Code\n```\nclass Solution {\npublic:\n    int lengthOfLongestSubsequence(vector<int>& nums, int target) {\n        int n=nums.size();\n        vector<int> dp(1001);\n        for(int i=0 ; i<n ; i++){\n            for(int j=target-1 ; j>0 ; j--){\n                int curr_sum = j+nums[i];\n                if(dp[j] && curr_sum <= target){\n                    dp[curr_sum] = max(dp[curr_sum], 1+dp[j]);\n                }\n            }\n            dp[nums[i]] = max(dp[nums[i]], 1);\n        }\n        return dp[target]==0 ? -1 : dp[target];\n    }\n};\n```
['Dynamic Programming', 'C++']