We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsys# Complete the ways function below.defways(n,coins,m):t=[[0foriinrange(n+1)]forjinrange(m+1)]foriinrange(m+1):t[i][0]=1foriinrange(1,n+1):t[0][i]=0foriinrange(1,m+1):forjinrange(1,n+1):ifcoins[i-1]>j:t[i][j]=t[i-1][j]else:t[i][j]=t[i-1][j]+t[i][j-coins[i-1]]returnt[m][n]nm=input().split()n=int(nm[0])m=int(nm[1])coins=list(map(int,input().rstrip().split()))print(ways(n,coins,m))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
DP: Coin Change
You are viewing a single comment's thread. Return to all comments →