- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find number of ways we can get n R.s using Indian denominations in Python

Suppose we have limited coins of denominations (₹1, ₹2, ₹5 and ₹10). We have to find in how many ways can you sum them up to a total of ₹n? We have an array count of size 4, where count[0] indicates coins of ₹1, count[1] indicates coins of ₹2 and so on.

So, if the input is like n = 25 count = [7,3,2,2], then the output will be 9.

To solve this, we will follow these steps −

- denom := [1,2,5,10]
- A := an array of size (n + 1) and fill with 0
- B := a new list from A
- for i in range 0 to (minimum of count[0] and n), do
- A[i] := 1

- for i in range 1 to 3, do
- for j in range 0 to count[i], do
- for k in range 0 to n + 1 - j *denom[i], do
- B[k + j * denom[i]] := B[k + j * denom[i]] + A[k]

- for k in range 0 to n + 1 - j *denom[i], do
- for j in range 0 to n, do
- A[j] := B[j]
- B[j] := 0

- for j in range 0 to count[i], do
- return A[n]

## Example

Let us see the following implementation to get better understanding −

denom = [1,2,5,10] def solve(n, count): A = [0] * (n + 1) B = list(A) for i in range(min(count[0], n) + 1): A[i] = 1 for i in range(1, 4): for j in range(0, count[i] + 1): for k in range(n + 1 - j *denom[i]): B[k + j * denom[i]] += A[k] for j in range(0, n + 1): A[j] = B[j] B[j] = 0 return A[n] n = 25 count = [7,3,2,2] print(solve(n, count))

## Input

25, [7,3,2,2]

## Output

9

- Related Questions & Answers
- Program to find number of ways we can arrange symbols to get target in Python?
- Program to count number of ways we can throw n dices in Python
- Program to find maximum number of coins we can get using Python
- Program to find number of ways we can decode a message in Python
- Program to find number of ways we can split a palindrome in python
- Program to find number of ways we can reach to the next floor using stairs in Python
- Program to find number of ways we can concatenate words to make palindromes in Python
- Program to find number of ways we can get a number which is sum of nth power of unique numbers in Python
- Program to find number of ways we can select sequence from Ajob Sequence in Python
- Python program to find ways to get n rupees with given coins
- Program to count number of ways we can distribute coins to workers in Python
- Program to find how many ways we can climb stairs in Python
- Program to count number of ways we can fill 3 x n box with 2 x 1 dominos in Python
- Program to find number of ways we can reach from top left point to bottom right point in Python
- Program to find number of good ways to split a string using Python

Advertisements