DP - Classical Knapsack | C++
\n\n# Code\n\nclass Solution {\npublic:\n    int lengthOfLongestSubsequence(vector<int>& nums, int target){\n        vector<int> dp(target+1,0);\n        for(in
\n\n# Code\n```\nclass Solution {\npublic:\n    int lengthOfLongestSubsequence(vector<int>& nums, int target){\n        vector<int> dp(target+1,0);\n        for(int num : nums) \n            for(int t=target;t>=num;t--) \n                if(t-num == 0 || dp[t-num]) \n                    dp[t] = max(dp[t],1+dp[t-num]);\n        return dp[target] ? dp[target] : -1;\n    }\n};\n```
['C++']