Write a C code for
Modified Change problem:
Apply the dynamic programming algorithm to find all the solutions to the change-making problem for the denominations 1, 3, 5 and the amount n = 9
Code in c
#include<stdio.h>
#include<string>
int possiblewayschangeorder(int changemakingcoinorder[], int dcoinssize, int n);
int main()
{
int denominationcoins[] = {1, 3, 5};
int dcoinssize = sizeof(denominationcoins) / sizeof(denominationcoins[0]);
int n = 9;
printf("%d", possiblewayschangeorder(denominationcoins, dcoinssize, n));
return 0;
}
int possiblewayschangeorder(int changemakingcoinorder[], int dcoinssize, int n)
{
int coin, making;
int changemaking[n + 1][dcoinssize];
for (int i = 0; i < dcoinssize; i++)
changemaking[0][i] = 1;
for (int i = 1; i < n + 1; i++)
{
for (int j = 0; j < dcoinssize; j++)
{
coin = (i - changemakingcoinorder[j] >= 0) ? changemaking[i - changemakingcoinorder[j]][j] : 0;
making = (j >= 1) ? changemaking[i][j - 1] : 0;
changemaking[i][j] = coin + making;
}
}
return changemaking[n][dcoinssize - 1];
}\
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT
SECTION
Write a C code for Modified Change problem: Apply the dynamic programming algorithm to find all...
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...
Can you answer #3? 2. (12 marks) Use dynamic programming for the following 'Make Change problem': Number of denominations, N: 4 Denomination values, dl : 7, 2, 3,6 Amount for which change is to be made, A: 17. how the values of arrays Cl and SI (shown in class) for each denomination or iteration. 3. (8 marks) Implement Make Change problem' using dynamic programming and homw the outut fort he gdgg show the output for the input from Question 2....
Rod-cutting problem Design a dynamic programming algorithm for the following problem. Find the maximum total sale price that can be obtained by cutting a rod of n units long into integer-length pieces if the sale price of a piece i units long is pi for i = 1, 2, . . . , n. What are the time and space efficiencies of your algorithm? Code or pseudocode is not needed. Just need theoretical explanation with dynamic programming with recurrence relation...
1. Apply the dynamic programming algorithm discussed in class to solve the knapsack problem. (10 points) a. Show the completed table. b. Which items are included in the final configuration of the knapsack? c. What is the maximum value that can fit in the knapsack using a configuration of these items? item 1 2. 3 4 weight 3 2 value $25 $20 $15 1 capacity W = 6. 4 5 $40 $50 5
Design a dynamic programming algorithm for the problem. Define the original problem as a function that takes parameters, and return some results. Define the subproblems Write recursive formula that relates a problem's solution to solutions of smaller subproblems. Finally write out pseudocode for the algorithm (using top-down memoization or bottom-up) Suppose a list Р[L..n] gives the daily stock price of a certain company for a duration of n days, we want to find an optimal day di to buy the...
A) Write the pseudocode for an algorithm using dynamic programming to solve the activity-selection problem based on this recurrence: c[i, j] = 0 if Si; = Ø max {c[i, k] + c[k,j] + 1} if Sij +0 ak eSij B) Analyze the running time (the time complexity) of your algorithm and compare it to the iterative greedy algorithm.
1. Write the algorithm pseudocode for the longest common subsequence problem using dynamic programming. What is its running time?
Prove that your algorithm works! 6.) Dynamic Consider a modification of the rod-cutting problem in which, in addition to a price p, for each rod, each cut incurs a fixed cost of c. The revenue associated with a solution is now the sum of the prices of the pieces minus the costs of making the cuts. Give a dynamic-programming algorithm to solve this modified problem. Prove that your algorithm works.
3. Apply the dynamic programming algorithm discussed in class to solve the knapsack problem. (20 points) a. Show the completed table. b. Which items are included in the final configuration of the knapsack? c. What is the maximum value that can fit in the knapsack using a configuration of these items? Item 1 weighs 2 pounds and is worth $9.00 Item 2 weighs 3 pounds and is worth $12.00 Item 3 weighs 5 pounds and is worth $14.00 Item 4...
a) Implement the bottom-up dynamic programming algorithm for the knapsack problem in python. The program should read inputs from a file called “data.txt”, and the output will be written to screen, indicating the optimal subset(s). b) For the bottom-up dynamic programming algorithm, prove that its time efficiency is in Θ(nW), its space efficiency is in Θ(nW) and the time needed to find the composition of an optimal subset from a filled dynamic programming table is in O(n). Consider the following...