ProgrammingVery hardGATE CS & IT · Infosys
What is printed?
What is printed?
def ways(coins, amt):
dp = [0] * (amt + 1)
dp[0] = 1
for c in coins:
for v in range(c, amt + 1):
dp[v] += dp[v - c]
return dp[amt]
print(ways([1, 2, 5], 5), ways([2, 5], 3))- A. 5 0
- B. 4 0
- C. 4 1
- D. 3 0
Correct answer: B. 4 0
This is unordered coin-change counting. 5 can be made as {5}, {2,2,1}, {2,1,1,1} and {1,1,1,1,1}, and 3 cannot be made from coins 2 and 5.
More Python Programming questions
- What is printed? python def lcs(a, b): dp = [[0] (len(b) + 1) for in range(len(a) + 1)] for i in range(1, len(a) + 1): for j in range(1…
- What is printed? python items = [(60, 10), (100, 20), (120, 30)] cap = 50 best = 0 w = 0 for v, wt in sorted(items, key=lambda x: x[0] /…
- What is printed? python def mincapacity(w, days): lo, hi = max(w), sum(w) while lo < hi: mid = (lo + hi) // 2 need, cur = 1, 0 for x in w…
- What is printed? python from functools import lrucache @lrucache(maxsize=2) def sq(x): return x x for v in [1, 2, 1, 3, 1]: sq(v)…
- What is printed? python def nge(a): res = [-1] len(a) st = [] for i, x in enumerate(a): while st and a[st[-1]] < x: res[st.pop()] = x…
- What is printed? python def pickbystart(iv): iv = sorted(iv) cnt, end = 0, -109 for s, e in iv: if s >= end: cnt += 1 end = e return cnt…