def knapsack_unbounded(w, wt, vt, n):
    """
    It's an unbounded knapsack problem as we can use 1 or more instances of
    any resource. A simple 1D array, say dp[W+1] can be used such that dp[i]
    stores the maximum value which can achieved using all items and i capacity
    of knapsack. Note that we use 1D array here which is different from
    classical knapsack where we used 2D array. Here number of items never
    changes. We always have all items available.

    We can recursively compute dp[] using below formula

    - dp[i] = 0
    - dp[i] = max(dp[i], dp[i-wt[j]] + val[j]

    where j varies from 0 to n-1 such that: wt[j] <= i

    :param w: total capacity
    :type w: int
    :param wt: weight of each element
    :type wt: list[int]
    :param vt: value of each element
    :type vt: list[int]
    :param n: number of elements
    :type n: int
    :return: the maximum value that can be put in a knapsack of capacity w
    :rtype: int
    """
    # dp[i] is going to store maximum value with knapsack capacity i
    dp = [0 for _ in range(w + 1)]
    # fill dp[] using above recursive formula
    for w_idx in range(w + 1):
        for n_idx in range(n):
            if wt[n_idx] <= w_idx:
                dp[w_idx] = max(dp[w_idx], dp[w_idx - wt[n_idx]] + vt[n_idx])
    return dp[w]