Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.23 KB | None | 0 0
  1. EECS 281 Autograder
  2. Home
  3. Queue
  4. FAQ
  5. Logged in as kavinp
  6. F18H10 output (18.12.12.165442)
  7. Back to project • Download submission
  8.  
  9. - - -
  10. Please keep in mind that the autograder does not assign grades. Project grades
  11. also take style, efficiency, and other deliverables into account. Test cases
  12. used for grading may be completely different than those used to evaluate trial
  13. submissions.
  14. - - -
  15.  
  16. Checking for unexpected file patterns:
  17. (Note: any file with two leading underscores or the extensions
  18. .o, .stderr, .stdout will be deleted. Case will be ignored)
  19.  
  20. -------------------------------------------------------------------------------
  21. Performing static analysis with [cppcheck --language=c++ --enable=all --suppress=missingIncludeSystem *.c* *.h*]
  22.  
  23. [deals.h:45]: (style) The function 'discounted' is never used.
  24.  
  25. -------------------------------------------------------------------------------
  26. Checking for style errors:
  27.  
  28. Found 25713 tokens in source.
  29. if this number significantly exceeds the average reported for all students,
  30. your source code is too bloated and needs to be reduced in size.
  31. ----------------------------------------------------------------
  32. ./test-16-27.cpp: ASCII C program text
  33. Lines with more than 80 characters may not display or print well (line 20)
  34. Inconsistent brace style (lines 12,9)
  35. Choose between the following two styles and be consistent:
  36. if ( ... ) {
  37. or
  38. if ( ... )
  39. {
  40. ----------------------------------------------------------------
  41. ./deals.h: ASCII C++ program text
  42. Lines with more than 80 characters may not display or print well (line 6)
  43. ----------------------------------------------------------------
  44. ./samples.cpp: ASCII C program text
  45. Lines with more than 80 characters may not display or print well (line 31)
  46. Inconsistent brace style (lines 24,23)
  47. Choose between the following two styles and be consistent:
  48. if ( ... ) {
  49. or
  50. if ( ... )
  51. {
  52. Consider organizing the code in this file into several smaller files
  53. or using a less verbose coding style.
  54.  
  55. -------------------------------------------------------------------------------
  56. All expected files found
  57.  
  58. -------------------------------------------------------------------------------
  59. Build warnings/errors:
  60. In file included from test-16-27.cpp:5:0:
  61. deals.h: In function ‘cost best_price(const std::vector<long long int>&)’:
  62. deals.h:51:42: warning: unused parameter ‘prices’ [-Wunused-parameter]
  63. cost best_price(const std::vector<cost>& prices) {
  64. ^~~~~~
  65.  
  66.  
  67. ===============================================================================
  68. Scoring student executable...
  69.  
  70.  
  71. Test case MEAL18: Failed
  72. Runtime (sec): 0.002/0.004
  73. Memory (kb): 1436/2264
  74. Line: 1
  75.  
  76. -------------------------------------------------------------------------------
  77. Test case MEAL25: Failed
  78. Runtime (sec): 0.003/0.004
  79. Memory (kb): 1432/2127
  80. Line: 1
  81.  
  82. -------------------------------------------------------------------------------
  83. Test case MEAL27: Failed
  84. Runtime (sec): 0.002/0.004
  85. Memory (kb): 1436/2176
  86. Line: 1
  87.  
  88. -------------------------------------------------------------------------------
  89. Test case MEAL16: Failed
  90. Runtime (sec): 0.002/0.006
  91. Memory (kb): 1452/2584
  92. Line: 1
  93.  
  94. -------------------------------------------------------------------------------
  95. Test case MEAL24: Failed
  96. Runtime (sec): 0.002/0.006
  97. Memory (kb): 1440/2643
  98. Line: 1
  99.  
  100. -------------------------------------------------------------------------------
  101. Test case MEAL17: Failed
  102. Runtime (sec): 0.002/0.009
  103. Memory (kb): 1464/3343
  104. Line: 1
  105.  
  106. -------------------------------------------------------------------------------
  107. Test case MEAL21: Failed
  108. Runtime (sec): 0.002/0.009
  109. Memory (kb): 1448/3319
  110. Line: 1
  111.  
  112. -------------------------------------------------------------------------------
  113. Test case MEAL20: Failed
  114. Runtime (sec): 0.002/0.010
  115. Memory (kb): 1448/3425
  116. Line: 1
  117.  
  118. -------------------------------------------------------------------------------
  119. Test case MEAL26: Failed
  120. Runtime (sec): 0.002/0.024
  121. Memory (kb): 1476/6296
  122. Line: 1
  123.  
  124. -------------------------------------------------------------------------------
  125. Test case MEAL23: Failed
  126. Runtime (sec): 0.002/0.067
  127. Memory (kb): 1560/13820
  128. Line: 1
  129.  
  130. -------------------------------------------------------------------------------
  131. Test case MEAL22: Failed
  132. Runtime (sec): 0.003/0.116
  133. Memory (kb): 1632/21351
  134. Line: 1
  135.  
  136. -------------------------------------------------------------------------------
  137. Test case MEAL19: Failed
  138. Runtime (sec): 0.003/0.185
  139. Memory (kb): 1744/31755
  140. Line: 1
  141.  
  142. *@@@@@@#(/////////, Hi there! My name is Otto, and I am one of the Autograder
  143. /@@@@(//////////////*,.... parrots in charge of running the Autograder. It seems that
  144. (@@@#//////////////,........... you have requested help on the DP problem of Lab 10. Well,
  145. @@@(//////////////*,.............. if you did, you're in the right place!
  146. @@%///////////////,,,,,,,,,,........
  147. .,,,. @@////////////////,,,,,,,,,,,,,,...... Let's look at the problem at hand and figure out why dynamic
  148. .@@@@@@@@* #@//, //////,,,,,,,,,,,,,,,,,..... programming may be useful here. At this restaurant, you
  149. .@@@@@@@@( @// %@@@/*///*,,,,,,,,,,,,,,,,,,.... essentially have two options for every meal. You can either
  150. ,@@@@@@@/// .@ @@@.///,,,,,,,,,,,,,,,,,,,,... purchase a meal at full price and get a stamp on your loyalty
  151. .&@@@@@@@@@@@@/// (@@@@@@///*,,,,,,,,,,,,,,,,,,,,,.. punch card, or you can forgo an extra stamp by applying a
  152. ,@@@@@@@@@@@@@&.////, &@@@@(///,,,,,,,,,,,,,,,,,,,,,,,. coupon to your meal instead. If you collect five stamps, you
  153. .,*,. ///////////,,,,,,,,,,,,,,,,,,,,,,,,,,,,. get a free meal! As a result, there is a tradeoff you have to
  154. //////////*,,,,,,,,,,,,,,,,,,,,,,,,,,,. make at every meal - should you collect an extra stamp to get
  155. ,//////////*,,,,,,,,,,,,,,,,,,,,,,,,. closer to that free meal, or should you apply a discount on
  156. .*////////*,,,,,,,,,, . your current meal instead?
  157. **. */, /////(/////////
  158. ///**//,//## ////////#////////. Well, it all depends! If you are 1 stamp away from a free
  159. ,*///####////////(//////// meal, and you know that your next meal will be expensive, you
  160. ///////////(///////* would definitely want to collect your last stamp today! But
  161. ,///////(//////// if you know that the next meal will be cheap, you have more
  162. .////////((////////* freedom to wait, so you may want to use a coupon and get a
  163. **////////***** small price discount today. But what if you had fewer stamps?
  164. .*********. *******, If you had 3 stamps, and you knew that the meal after the
  165. .*** ** next will be expensive, you would collect stamps on the next
  166. two meals to get that expensive meal for free.
  167.  
  168. This is where the overlapping subproblems come into play. Your decision to get an immediate discount or collect a stamp relies
  169. on the prices of the meals and the number of stamps you have so far. Let's look at an example to see how this all works.
  170.  
  171. Suppose our meals cost {3, 3, 3, 3, 3, 3, 100}. To help you visualize the process, let's build a table that keeps track of our
  172. total costs after each decision. We'll consider the first meal as Meal 0 for the sake of C++ indexing.
  173.  
  174. +----------+-------------------------------------------------------------------------------------------------+
  175. | | Meal # |
  176. +----------+-------------------------------------------------------------------------------------------------+
  177. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  178. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  179. | 0 | | | | | | | |
  180. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  181. | 1 | | | | | | | |
  182. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  183. | 2 | | | | | | | |
  184. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  185. | 3 | | | | | | | |
  186. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  187. | 4 | | | | | | | |
  188. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  189. | 5 | | | | | | | |
  190. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  191.  
  192. Let's consider the two base cases, [S0, M0] and [S1, M0]. If you had Meal 0 and ended up with zero stamps, what must have
  193. happened? You must have used a coupon since you ended up with no stamps! Thus, [S0, M0] has a value of discounted(3), or 2.
  194.  
  195. If you had Meal 0 and ended up with one stamp, what must have happened? You must have used a stamp on Meal 0, since you have
  196. one stamp after this first meal. Because of this, [S1, M0] has a value of the full price of Meal 0, or 3. This gives us
  197.  
  198. +----------+-------------------------------------------------------------------------------------------------+
  199. | | Meal # |
  200. +----------+-------------------------------------------------------------------------------------------------+
  201. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  202. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  203. | 0 | 2 | | | | | | |
  204. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  205. | 1 | 3 | | | | | | |
  206. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  207. | 2 | | | | | | | |
  208. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  209. | 3 | | | | | | | |
  210. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  211. | 4 | | | | | | | |
  212. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  213. | 5 | | | | | | | |
  214. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  215.  
  216. Now let's see if we can find a pattern for the rest of the meals. What if we kept moving horizontally in row S0? If we did
  217. this, we would be ordering meals without changing our stamp count; in this case, we must have used a coupon on the meal to
  218. have moved right but not down. Because each of the first five meals costs $3, moving right simply means that we are paying
  219. the discounted price ($2) at every meal. Thus, we keep on adding 2 as we move along row S0 up to Meal 5 (since you could
  220. have used a stamp to get to [S0, M5]).
  221.  
  222. +----------+-------------------------------------------------------------------------------------------------+
  223. | | Meal # |
  224. +----------+-------------------------------------------------------------------------------------------------+
  225. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  226. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  227. | 0 | 2 | 2 + 2 = 4 | 4 + 2 = 6 | 6 + 2 = 8 | 8 + 2 = 10 | | |
  228. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  229. | 1 | 3 | | | | | | |
  230. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  231. | 2 | | | | | | | |
  232. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  233. | 3 | | | | | | | |
  234. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  235. | 4 | | | | | | | |
  236. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  237. | 5 | | | | | | | |
  238. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  239.  
  240. What if we got a stamp? In that case, we would move down one row at the cost of one fully priced meal. Because of this, to
  241. move down one row every time we move to the next meal, we would have to pay the full price, or $3. This is shown below.
  242.  
  243. +----------+-------------------------------------------------------------------------------------------------+
  244. | | Meal # |
  245. +----------+-------------------------------------------------------------------------------------------------+
  246. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  247. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  248. | 0 | 2 | 4 | 6 | 8 | 10 | | |
  249. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  250. | 1 | 3 | X | | | | | |
  251. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  252. | 2 | | 3 + 3 = 6 | | | | | |
  253. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  254. | 3 | | | 6 + 3 = 9 | | | | |
  255. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  256. | 4 | | | | 9 + 3 = 12 | | | |
  257. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  258. | 5 | | | | | 12 + 3 = 15 | | |
  259. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  260.  
  261. But what about the cell that has been marked with an X above? What is the lowest cost to get to that point (1 stamp after
  262. 1 meal)? The answer to this depends on two other cells in the table. For the cell marked with an X, you must ask the question:
  263. is it cheaper to get to that cell by collecting a stamp on the meal (at full price) or by purchasing the meal on a discount
  264. (coupon)? In the case of the X, the total cost of applying a coupon can either be 3 + 2, where 3 is the total cost accumulated
  265. after the previous meal ([S1, M0]), and 2 is the cost of the current meal (0.75 of the full price), or it can be 2 + 3, where
  266. 2 is the cost accumulated after the previous meal when the stamp count is one fewer than the count you have now ([S0, M0]), and
  267. 3 is the cost of the current meal, under the condition that you paid full price for the meal for an additional stamp on your
  268. punchcard. Since both of these possibilities yield a total cost of 5, the value of cell [S1, M1] is 5. If the two scenarios
  269. above (cost of applying the coupon vs. cost of paying full price for a stamp) produce different results, you would choose the
  270. smaller of the two (since you want to minimize costs). Repeating this for the cells up to Meal 4 produces the following:
  271.  
  272. +----------+-------------------------------------------------------------------------------------------------+
  273. | | Meal # |
  274. +----------+-------------------------------------------------------------------------------------------------+
  275. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  276. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  277. | 0 | 2 | 4 | 6 | 8 | 10 | | |
  278. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  279. | 1 | 3 | 3 + 2 = 5 | 5 + 2 = 7 | 7 + 2 = 9 | 9 + 2 = 11 | | |
  280. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  281. | 2 | | 6 | 6 + 2 = 8 | 8 + 2 = 10 | 10 + 2 = 12 | | |
  282. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  283. | 3 | | | 9 | 9 + 2 = 11 | 11 + 2 = 13 | | |
  284. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  285. | 4 | | | | 12 | 12 + 2 = 14 | | |
  286. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  287. | 5 | | | | | 15 | | |
  288. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  289.  
  290. Here is the table up to Meal 4 (the 5th meal we had). The reason the first 5 meals were separated is that at this point, a full
  291. punchcard with a free meal isn't yet an option.
  292.  
  293. +----------+-------------------------------------------------------------------------------------------------+
  294. | | Meal # |
  295. +----------+-------------------------------------------------------------------------------------------------+
  296. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  297. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  298. | 0 | 2 | 4 | 6 | 8 | 10 | X | |
  299. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  300. | 1 | 3 | 5 | 7 | 9 | 11 | | |
  301. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  302. | 2 | | 6 | 8 | 10 | 12 | | |
  303. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  304. | 3 | | | 9 | 11 | 13 | | |
  305. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  306. | 4 | | | | 12 | 14 | | |
  307. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  308. | 5 | | | | | 15 | | |
  309. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  310.  
  311. So what is the cost of the box marked with an X above (Meal 5 with 0 stamps)? If we move right from row S0, this value would
  312. be 10 + discounted(M5), or 10 + 2 = 12. But we could have also used our free punch card for Meal 5 in order to get it for free!
  313. Well, what would be the cost of getting to that point? In order to get Meal 5 free, we must have paid the full price for the
  314. previous 5 meals, for a total cost of 15 (the value at [S5, M4]).
  315.  
  316. Thus, the value of X can either be 12 (just used a coupon all the way through) or 15 (using the punchcard to get the meal for
  317. free). So which is it? Obviously, we would choose the one with the lowest cost! If we could get to a position with just $12, why
  318. would we pay $15? So the value of X is 12, and our updated table is:
  319.  
  320. +----------+-------------------------------------------------------------------------------------------------+
  321. | | Meal # |
  322. +----------+-------------------------------------------------------------------------------------------------+
  323. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  324. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  325. | 0 | 2 | 4 | 6 | 8 | 10 | 12 | |
  326. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  327. | 1 | 3 | 5 | 7 | 9 | 11 | Y | |
  328. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  329. | 2 | | 6 | 8 | 10 | 12 | | |
  330. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  331. | 3 | | | 9 | 11 | 13 | | |
  332. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  333. | 4 | | | | 12 | 14 | | |
  334. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  335. | 5 | | | | | 15 | | |
  336. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  337.  
  338. Now, what is the value of Y? We could use a coupon; in this case, we would go from Meal 4 to Meal 5 without changing the row we
  339. are in. This would just be $11 (the cost of the ending up at Meal 4 with just 1 stamp), so the cost of Y could be this cost
  340. ($11) plus the discounted price of Meal 5 (discounted(3), or $2), or $11 + $2 = $13.
  341.  
  342. But what could Y also be? What if we had gotten a stamp on Meal 5? In this case, before Meal 5, we must have had 0 stamps (as
  343. Meal 5 would get us to 1 stamp). How much does it cost to get here? The cost of getting to Meal 4 with 0 stamps, or $10. Thus,
  344. to get the extra stamp, we would have paid the full $3 for Meal 5, so the value of Y would be $10 + $3 = $13 in this scenario.
  345.  
  346. We would choose the minimum in this case, but since both options give us the same cost, the value of Y must be $13.
  347.  
  348. This is the pattern you want:
  349.  
  350. For each box, you could have either used a stamp at the full price ...
  351. for which the cost to get there would be table[numStamps - 1][numMeals - 1] + full price of meal ...
  352.  
  353. ... or you could have just used a coupon without changing the number of stamps you have ...
  354. for which the cost to get there would be table[numStamps][numMeals - 1] + discounted price of meal ...
  355.  
  356. However, there is a special case:
  357. For the boxes in row 0 after your 5th meal, you have two different options to minimize:
  358.  
  359. For each box in row 0 (no stamps currently), you could have used a coupon ...
  360. for which the cost to get there would be table[numStamps][numMeals - 1] + discounted price of meal ...
  361.  
  362. ... or you could have cashed in a full punchcard with five stamps ...
  363. for which the cost to get there would be table[5][numMeals - 1] + 0 ... since you got the meal for free!
  364.  
  365. From here, you would then choose the minimum value as the cost for each box. Meal 5 is finished in the table below.
  366.  
  367. +----------+-------------------------------------------------------------------------------------------------+
  368. | | Meal # |
  369. +----------+-------------------------------------------------------------------------------------------------+
  370. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  371. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  372. | 0 | 2 | 4 | 6 | 8 | 10 | 12 | Z |
  373. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  374. | 1 | 3 | 5 | 7 | 9 | 11 | 13 | |
  375. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  376. | 2 | | 6 | 8 | 10 | 12 | 14 | |
  377. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  378. | 3 | | | 9 | 11 | 13 | 15 | |
  379. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  380. | 4 | | | | 12 | 14 | 16 | |
  381. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  382. | 5 | | | | | 15 | 17 | |
  383. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  384.  
  385. Now let's consider Meal 6, which is a whopping $100! What could the value of Z be? Once again, let's look at your options.
  386.  
  387. You could have used a coupon, for which the cumulative price would be $12 + discounted($100), or $87. Or, you could have spent
  388. $17 to put yourself in a situation where you had a full punchcard to pay for that $100 meal for free. So what do you choose?
  389. Obviously the $17!
  390.  
  391. Let's finish our last meal. We pay fullprice(100) if we want an additional stamp after the previous meal, or discount(100) if we
  392. want to use a coupon instead of getting a stamp. The results are shown in the table below, which only includes Meals 4, 5, and 6.
  393.  
  394. +----------+---------------------------------------------------------------------------+
  395. | | Meal # |
  396. +----------+---------------------------------------------------------------------------+
  397. | # Stamps | 4 | 5 | 6 |
  398. +----------+----------+----------+-----------------------------------------------------+
  399. | 0 | 10 | 12 | MIN(17, 12 + DISCOUNT(100) = 87) = 17 |
  400. +----------+----------+----------+-----------------------------------------------------+
  401. | 1 | 11 | 13 | MIN(12 + 100 = 112, 13 + DISCOUNT(100) = 88) = 88 |
  402. +----------+----------+----------+-----------------------------------------------------+
  403. | 2 | 12 | 14 | MIN(13 + 100 = 113, 14 + DISCOUNT(100) = 89) = 89 |
  404. +----------+----------+----------+-----------------------------------------------------+
  405. | 3 | 13 | 15 | MIN(14 + 100 = 114, 15 + DISCOUNT(100) = 90) = 90 |
  406. +----------+----------+----------+-----------------------------------------------------+
  407. | 4 | 14 | 16 | MIN(15 + 100 = 115, 16 + DISCOUNT(100) = 91) = 91 |
  408. +----------+----------+----------+-----------------------------------------------------+
  409. | 5 | 15 | 17 | MIN(16 + 100 = 116, 17 + DISCOUNT(100) = 92) = 92 |
  410. +----------+----------+----------+-----------------------------------------------------+
  411.  
  412. It is better to discount the $100 meal than pay full price for a stamp, so we get a final table of:
  413.  
  414. +----------+-------------------------------------------------------------------------------------------------+
  415. | | Meal # |
  416. +----------+-------------------------------------------------------------------------------------------------+
  417. | # Stamps | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
  418. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  419. | 0 | 2 | 4 | 6 | 8 | 10 | 12 | 17 |
  420. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  421. | 1 | 3 | 5 | 7 | 9 | 11 | 13 | 88 |
  422. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  423. | 2 | | 6 | 8 | 10 | 12 | 14 | 89 |
  424. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  425. | 3 | | | 9 | 11 | 13 | 15 | 90 |
  426. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  427. | 4 | | | | 12 | 14 | 16 | 91 |
  428. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  429. | 5 | | | | | 15 | 17 | 92 |
  430. +----------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
  431.  
  432. Hence, after finishing Meal 6, we could have spent a total of $17, $88, $89, $90, $91, or $92. Which is the best? You would
  433. look in this final column for the minimum value... in this case, it's simple: you would definitely pay $17 for six meals
  434. rather than nearly $100, so the answer in this case would be $17.
  435.  
  436. You may use this approach to tackle this problem, and if you implement it correctly, you will be able to obtain the correct
  437. answer for all 27 test cases, 15 public and 12 private. This is a bottom-up solution to this problem - a top-down solution
  438. would also work. I wish you the very best on this lab and the rest of EECS 281. Good luck!
  439.  
  440. Last updated November 21, 2018
  441.  
  442. -------------------------------------------------------------------------------
  443. You passed 0 out of 12 test cases, earning 0.00 of 10.00 points
  444.  
  445.  
  446. ===============================================================================
  447.  
  448. Total points earned: (0.00 for code) + (0.0 for test files) = 0.00 of 10.00 points
  449. By using the autograder, you agree that you will not try to circumvent autograder limitations to gain an unfair advantage over other students in any way. Doing so constitutes an Honor Code violation and will be directly forwarded to the Engineering Honor Council.
  450.  
  451. Bug reports? Feature requests? eecs281ag@umich.edu
  452.  
  453. Copyright © 2009–2018 College of Engineering at the University of Michigan, Ann Arbor, MI 48109.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement