1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Paul [167]
3 years ago
8

(a) Write a SCHEME function (make-change n den) which outputs a list of change specifications. Namely, a call (make-change 11 (l

ist 25 10 5 1) produces the list
((1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 5) (1 5 5) (1 10))
Hints: a helper function (helper n den cur) that takes as input cur, a list of coins given out so far will surely come in handy! Also, the order in which the "options" appear in the top list is immaterial.

(b) While getting the output above is helpful, it is not particularly readable. Indeed, the list (1 1 1 1 1 1 5) that states 6 pennies and 1 nickel could be far more readable as ((6 . 1) (1 . 5)) also stating 6 pennies and 1 nickel. That is, this is a list of pairs telling us how many of each denomination. Thankfully, the former can be translated into the latter by a conversion known as run length encoding that replaces sequences of an identical value by a pair giving the number of repetition of the value.
Write a SCHEME function (rle coins) which, given a list of coins, returns a list of pairs denoting the number of repetitions of each sequence of consecutive values. As a last example, the list
(list 1 1 1 1 1 1 1 5 5 5 5 1 1 1 10 10 10 1 1 25 25 25 25 25 25)
would be encoded as
( (17. 1) (4.5) (3 . 1) (3. 10) (2 . 1) (6. 25) )
Note how the tree sub-sequences of pennies are not collapsed into a single value. Those are kept as separate pairs. Naturally, this function only works for one element of the output from make-change.
Computers and Technology
1 answer:
pentagon [3]3 years ago
7 0

Answer:

#include <iostream>

using namespace std;

// Function to find the total number of ways to get change of N

// from unlimited supply of coins in set S

int count(int S[], int n, int N)

{

// if total is 0, return 1

if (N == 0)

 return 1;

// return 0 if total become negative

if (N < 0)

 return 0;

// initialize total number of ways to 0

int res = 0;

// do for each coin

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

{

 // recur to see if total can be reached by including

 // current coin S[i]

 res += count(S, n, N - S[i]);

}

// return total number of ways

return res;

}

// Coin Change Problem

int main()

{

// n coins of given denominations

int S[] = { 1, 2, 3 };

int n = sizeof(S) / sizeof(S[0]);

// Total Change required

int N = 4;

cout << "Total number of ways to get desired change is "

  << count(S, n, N);

return 0;

}

You might be interested in
Iciples UI
Dmitriy789 [7]

Answer:A

Explanation: I took the test !

8 0
3 years ago
A good algorithm should have which three components?
laila [671]

Answer:

a good algorithm must be able to accept a set of defined input. Output: a good algorithm should be able to produce results as output, preferably solutions. Finiteness: the algorithm should have a stop after a certain number of instructions. Generality: the algorithm must apply to a set of defined inputs.Explanation:

7 0
3 years ago
HELP! Answer to question 2?
Vesnalui [34]
One advantage of Binary Search Algorithm: 
Compared to Linear search it is much faster because linear search starts its searching right from the first value but binary searches for something by splitting the array in two again and again and again. 

One disadvantage of Binary Search Algorithm:
Have to be sorted, unlike linear search that doesn't have to be. 
4 0
4 years ago
What are voter purges
diamong [38]

Answer:

Voter registration lists, also called voter rolls, are the gateway to voting because a citizen typically cannot cast a vote that will count unless his or her name appears on the voter registration rolls. State and local officials regularly remove—or purge—citizens from voter rolls. In fact, 39 states and the District of Columbiareported purging more than 13 million voters from registration rolls between 2004 and 2006.

Explanation:

7 0
4 years ago
Which tools are found in the Quick Analysis feature? Check all that apply.
a_sh-v [17]

Answer:

A, C, E

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • To configure a router / modem, what type of IP interface configuration should you apply to the computer you are using?
    8·1 answer
  • Which is an internet service?<br><br> Antivirus<br> Chat<br> Firewall<br> Router
    8·2 answers
  • When projecting a presentation on a large screen, what should your minimum font size be?
    6·2 answers
  • 4. Write an appropriate comment for describ-
    11·1 answer
  • Write a program that will print out statistics for eight coin tosses. The user will input either an "h" for heads or a "t" for t
    14·1 answer
  • PLEASE HELP ASAP<br> Which technology encrypts traffic between a web browser and a website?
    10·2 answers
  • Write a program to enter a number and test if it is greater than 45.6. If the number entered is greater than 45.6, the program n
    10·1 answer
  • Which printer are used to print text and graphics with high speed ​
    15·1 answer
  • In one to two sentences, describe how you would add a new slide to your presentation.
    11·2 answers
  • What are good reasons to do yearly disaster recovery testing? check all that apply
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!