Question

Using Java programming languague find the total number of different coin changes to make change for...

Using Java programming languague find the total number of different coin changes to make change for N cents, and we have infinite supply of each of S = {5, 2, 1} valued coins.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Arrays;

class CoinChange

{

    static long countWays(int S[], int m, int n)

    {

        long[] table = new long[n+1];

        Arrays.fill(table, 0);   //O(n)

        table[0] = 1;

        for (int i=0; i<m; i++)

            for (int j=S[i]; j<=n; j++)

                table[j] += table[j-S[i]];

return table[n];

    }

public static void main(String args[])

    {

        int arr[] = {5,2,1};

        int m = arr.length;

        int n = 4;

        System.out.println(countWays(arr, m, n));

    }

}

Add a comment
Know the answer?
Add Answer to:
Using Java programming languague find the total number of different coin changes to make change for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given a value V in cents, you need to make change using a minimum number of...

    Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply of quarters, nickels, dimes, and pennies. Find the minimum number of coins. Display the quantity of each coin and the total number of coins, similar to the example output below. Use global constant identifiers, of type unsigned int, for the values of quarters, nickels, dimes, and pennies. Example: const unsigned int QUARTER = 25: Do not use...

  • algebraic combinatoric 1. Let b be the number of ways to change 6 cents. Find the generating function ". For whi...

    algebraic combinatoric 1. Let b be the number of ways to change 6 cents. Find the generating function ". For which n we can actually change n cents this way (that is, bn > 0)? n cents using coins valued 4 and 1. Let b be the number of ways to change 6 cents. Find the generating function ". For which n we can actually change n cents this way (that is, bn > 0)? n cents using coins valued...

  • Recall the coin changing problem: given coins of denomination di zonks, where 1 = d1 <...

    Recall the coin changing problem: given coins of denomination di zonks, where 1 = d1 < d2 < ··· < dk, and infinitely many coins of each denomination, find the minimum number of coins needed to make exact change for n zonks. Here we ask a different problem. Each coin has a weight, the weight of each coin with denomination di being wi > 0. We want to make exact change while minimizing the total weight of the coins used....

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • Suppose we want to make change for n cents, using the least number of coins of...

    Suppose we want to make change for n cents, using the least number of coins of denominations 1, 10, and 25 cents. Consider the following greedy strategy: suppose the amount left to change is m; take the largest coin that is no more than m; subtract this coin's value from m, and repeat. Either give a counter example, to prove that this algorithm can output a non-optimal solution or prove that this algorithm always outputs an optimal solution.

  • 2. Write a function CHANGES(m) (in psudocode), which returns a minimal number of coins to get...

    2. Write a function CHANGES(m) (in psudocode), which returns a minimal number of coins to get a total of m cents. Constraints: There are four types of coins with values 1, 5, 10, and 25, respectively. The total amount of money m is within 1-99 cents. Examples: o CHANGES(3) 3: it takes at least 3 coins (1 cent each) to get a total of 3 cents. o CHANGES(6) 2: it takes at least 2 coins (a 5-cent coin and 1-cent...

  • Java programming language! 1. Tossing Coins for a Dollar For this assignment you will create a...

    Java programming language! 1. Tossing Coins for a Dollar For this assignment you will create a game program using the Coin class from Programming Challenge 12. The program should have three instances of the Coin class: one representing a quarter, one representing a dime, and one representing a nickel. When the game begins, your starting balance is $0. During each round of the game, the program will toss the simulated coins. When a coin is tossed, the value of the...

  • 1. Using generating functions, find the number of ways to make change for a $100 bill...

    1. Using generating functions, find the number of ways to make change for a $100 bill using only dollar coins and $1, $2, and $5 bills. explain in detail

  • USING RECURSIONN!!! JAVA CODE Coin game: Alice and Bob are playing a game using a bunch...

    USING RECURSIONN!!! JAVA CODE Coin game: Alice and Bob are playing a game using a bunch of coins. The players pick several coins out of the bunch in turn. Each time a player is allowed to pick 1, 2 or 4 coins, and the player that gets the last coin is the winner. Assume that both players are very smart and he/she will try his/her best to work out a strategy to win the game. For example, if there are...

  • Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume...

    Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume that the coins with which you make change are quarters, dimes, nickels and pennies. Thus you are going to set n = 4 in your program. The amount k for which you have to make change will be provided by the user and your program will return the minimum number of coins needed and also the break-up of the change in terms of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT