category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

Combination Sum IV, Unbounded knapsack, 1D

class Solution {
    public:
    int combinationSum4(vector<int>& nums, int target) {
        vector<unsigned long long int> dp(target + 1, 0);
        dp[0] = 1;

        for (int i = 0; i <= target; i++) {

            for (const auto& c: nums) {
                if (c <= i) {
                    dp[i] += dp[i - c];
                }
            }

        }
        return dp[target];

    }
};