CS3343/3341 Analysis of Algorithms Spring 2012 |
Recitation 7, Question 5
Extended Hints |
I'm really confused about question 5 on recitation 7. We are first to take out the second condition from calcWork (i.e. (W[k] != a)), and also the fourth condition from calcWork (i.e. (W[k + a] == -1)). Then we are to make another array C that runs "parallel" to the array W. After that, I'm lost as to what to do. After taking off the two conditions and running the function say on A = {1,9,5,3,8}, with a work array of 27 and trying to find sums that add up to 13, the function doesn't seem to work well and gives me this as a result: W = {0,1,1,3,3,3,3,3,8,8,8, (all 8s) }. I don't know what I'm supposed to do with that information and how to tie in the C array to work parallel with W. I see that I'm supposed to find the least count of coins to add up to a certain number, but how do I do that with a modification of the calcWork function?
Possible #s <-------------------- W Array Index ----------------------------------------> in sum 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Initial: 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 {1}: 0 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 {1,9}: 0 1 -1 -1 -1 -1 -1 -1 -1 9 9 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 {1,9,5}: 0 1 -1 -1 -1 5 5 -1 -1 9 9 -1 -1 -1 5 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 {1,9,5,3}: 0 1 -1 3 3 5 5 -1 3 9 9 -1 3 3 5 5 -1 3 3 -1 -1 -1 -1 -1 -1 -1 -1 {1,9,5,3,8}: 0 1 -1 3 3 5 5 -1 3 9 9 8 3 3 5 5 8 3 3 -1 8 8 8 8 -1 8 8 |
Possible #s <-------------------- W Array Index ----------------------------------------> in sum 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Initial: 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 {1}: 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 {1,9}: 0 1 1 1 1 1 1 1 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 {1,9,5}: 0 1 1 1 1 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 {1,9,5,3}: 0 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 {1,9,5,3,8}: 0 1 1 3 3 3 3 3 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 |
Possible #s <-------------------- W Array Index ----------------------------------------> in sum 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Initial: 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 |