Question

Suppose you have a set of coins of various denominations, with values v1, v2, …, vn....

  1. Suppose you have a set of coins of various denominations, with values v1, v2, …, vn. Some of the coins may have the same value as other of the coins (or maybe not, for the purpose of this problem it doesn’t matter). I want to use these to buy an item that costs exactly M. That is, I want to find out if there is some subset of the coins whose values will sum to exactly M. (Note that I don’t care about minimizing the number of coins used, or finding out how many different sets of coins might have values that sum to M, I just want to find out if I have the exact cost of the item.)
    1. [5 pts] Write the recursion equation for this problem.
  1. [5 pts] Write short pseudocode that converts this equation into a dynamic program.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION :-

#include<stdio.h>
#include<stdlib.h>
struct node{
   int data;
   struct node *next;
};
void printlist(struct node *h){
   while(h != NULL){
       printf("%d ",h->data);
       h = h->next;
   }
}

int main(){
   struct node *start=NULL;
   int a,i;
   printf("Enter the no.of Nodes:");
   scanf("%d",&a);
   for(i=0;i<a;i++){
       struct node *newNode = (struct node *)malloc(sizeof(struct node));
       printf("Enter the data:");
       scanf("%d",&newNode->data);
       newNode->next = NULL;
       if(start==NULL)
           start = newNode;
       else{
           struct node *ptr = start;
           while(ptr->next!=NULL)
               ptr = ptr->next;
           ptr->next = newNode;
       }
   }
   printf("Linked List is:\n");
   printlist(start);
   printf("\nAfter sorting the list is:\n");
   struct node *s = start,*st = start;
   for(;s!=NULL;s = s->next){
       st = start;
       for(;st->next!=NULL;st = st->next){
           if(st->data>st->next->data){
               int te;
               te = st->data;
               st->data = st->next->data;
               st->next->data = te;
           }
       }
   }
   printlist(start);
}

Add a comment
Know the answer?
Add Answer to:
Suppose you have a set of coins of various denominations, with values v1, v2, …, vn....
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
  • Making Change: Given coins of denominations (value) 1 = v1 < v2< … < vn, we...

    Making Change: Given coins of denominations (value) 1 = v1 < v2< … < vn, we wish to make change for an amount A using as few coins as possible. Assume that vi’s and A are integers. Since v1= 1 there will always be a solution. Formally, an algorithm for this problem should take as input:  An array V where V[i] is the value of the coin of the ith denomination.  A value A which is the amount...

  • THIS QUESTION MUST BE ANWSERD WITH CLEAR ENGLISH PSEUDOCODE! You have a set of N coins...

    THIS QUESTION MUST BE ANWSERD WITH CLEAR ENGLISH PSEUDOCODE! You have a set of N coins in a bag, each having a value between 1 and M, where M ? N. Some coins may have the same value. You pick two coins (without replacement) and record the sum of their values. Determine(algorithm ) what possible sums can be achieved, in O(M log M ) time. For example, if there are N = 3 coins in the bag with values 1,...

  • The post office sells stamps of a variety of different denominations (values), and different sizes. Consider...

    The post office sells stamps of a variety of different denominations (values), and different sizes. Consider a set of n stamps, where each stamp i has a specific denomination di and a size si . All denominations are distinct. All input numbers are positive integers. We can use stamp denominations multiple times. When buying stamps that total to a given postage amount P, we want to minimize the total size of the stamps (to leave the most addressing space on...

  • Recall that in the "Knapsack Problem", there are n items having respective values V1..n) and weights...

    Recall that in the "Knapsack Problem", there are n items having respective values V1..n) and weights W1..n), all greater than 0 and one needs to maximize the total value of the subset of the items placed in the knapsack limited by a weight capacity of W In the 0-1 Knapsack Problem, each item must be either be included or excluded in its entirety, in light of the fact that this problem is to be "NP-Complete", how can one solve the...

  • Recursive backtracking: Suppose I want to burn some songs onto a 650MB CD (some people still...

    Recursive backtracking: Suppose I want to burn some songs onto a 650MB CD (some people still do!) and I have a list of song tracks of various sizes. I want to fill up as much of my CD as I can. I can use a recursive backtracking strategy to find a subset of the song tracks that optimally fills my CD (that is, with the least space left unfilled). You should recognise this problem as a version of the Knapsack...

  • In a Knapsack problem, given n items {I1, I2, · · · , In} with weight {w1, w2, · · · , wn} and value {v1,v2, ···, vn}, the goal is to select a combination of items such that the total value V is maxim...

    In a Knapsack problem, given n items {I1, I2, · · · , In} with weight {w1, w2, · · · , wn} and value {v1,v2, ···, vn}, the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity W . i-1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using . an...

  • (2) Suppose, the game is updated so that every item, i, now has weight, wi], in kilograms (you ca...

    Please help with question 2 (c). (2) Suppose, the game is updated so that every item, i, now has weight, wi], in kilograms (you can assume you are passed the item weights in an array, w, of size m). You can only carry n kilograms of weight. (a) (1 point) Example: Let n Ξ 15, m 5. If the item values are v (5.30, 17, 32, 40) and the item weights are w - 2,4, 3,6,15} which should you choose...

  • this assingent is to  pseudocode, i have instructions and the example my teacher had given me for...

    this assingent is to  pseudocode, i have instructions and the example my teacher had given me for this, could i have some assistance, i need to do this in netbeans IDE and i need to use the scanner method as well and i need to pass both. Overview: This assignment will allow you to use pseudocode to implement the program to see the value in planning first, coding later. While coding is the glamorous part of the job, software development is...

  • a=1.3661 and b=1.3483 according to table 2.3 6. (50 pts. Now that you have worked problem 9.46, you should have an unde...

    a=1.3661 and b=1.3483 according to table 2.3 6. (50 pts. Now that you have worked problem 9.46, you should have an understanding of the following problem, which is rather involved but is extremely instructive for understanding phase transitions in particular and equilibrium in general. a. Find the temperature at which N, boils at a pressure of 1 bar assuming N2 is well described by a van der Waals equation. Use the van der Waals constants given in Table 2(16).3. Compare...

  • The code is in python. The file does not have to be the data set from...

    The code is in python. The file does not have to be the data set from HW2. What I need is a code combing selection sort and merge sort. The 2-1 is what the problem in refers to as Q1. d) [10 points] Write a code combining both selection sort and mergesort algorithms (NOT insertion and merge sorts) as described in Q1) to find out the most optimal k minimizing time efficiency of your algorithms using 1 M data set...

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