Advertisement
Iam_Sandeep

Untitled

Aug 24th, 2022
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. class Solution:
  2.     def change(self, amount: int, coins: List[int]) -> int:
  3.         n=len(coins)
  4.         m=amount
  5.         dp=[[0]*(n+1) for i in range(m+1)]
  6.         for i in range(m+1):#amount
  7.             for j in range(n+1):#coins
  8.                 if i==0:
  9.                     dp[i][j]=1
  10.                 elif j==0:
  11.                     dp[i][j]=0
  12.                 else:
  13.                     excluded=dp[i][j-1]
  14.                     if i>=coins[j-1]:
  15.                         included=dp[i-coins[j-1]][j]
  16.                         print(included)
  17.                         dp[i][j]=included+excluded
  18.                     else:
  19.                         dp[i][j]=excluded
  20.         for i in dp:
  21.             print(i)
  22.         return dp[-1][-1]
  23.                        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement