i don't quite understand what the function choose_mem supposed to to, and how should it combine with choose. is it possible to explain in more detail? thanks!
choose_mem is a recursive function with memoizaiton. The memoization object is not global but rather an argument of the function which it keeps passing around. This is because we would have different memoization objects for different initial conditions (missions, time) and therefore it is different from fibonacci where the memoization object can be global.
choose is the function we "expose" to the user and this function simply calls choose_mem.
It's also not very clear how the answer to (a) should be written. Can you please provide an (unrelated to this specific question) example?
Can I assume that there aren't 2 missions with the same time/points? if not then what could be a unique key?
in part (a) of the question, if I want to get the given missions list without the last mission, is it ok to write m-m_n?
I didn't understand what is the parameter k in the function choose_mem.
We already pass the missions list with all the missions to choose from so why do we need k?
I also found it unnecessary but maybe by passing the length as a parameter we save the time of calculating a list's length every call?
Calculating list's length is simple arithmetic calculation.
Maybe by using k we can transfer the same missions list without
doing slicing which is O(n) time and memory and k which indicates
the last current mission?
Nimrod is correct.
By passing k you can pass around the *same* missions list but let the function know how many missions it can choose from. This is more efficient than slicing and creating new copies.
BTW Getting the length of a list is O(1) - the list keeps track of its length so there is no calculation involved (see here)
Is it allowed to use max in the expression for (a)? (without losing points for using it)
שלום, בקשר לסעיף א. לא הבנתי על אילו תנאי בסיס מדובר?
הצלחתי לממש את הקוד בסעיף ב והתכנית עובדת, אני מבין מה הנוסחא אמורה להיות (בהתאם לקוד התכנית) אך לא הצלחתי להבין מה הם תנאי הבסיס המדברים.
כלומר לכל בעיה יש את התנאים שלה כמו בכל נוסחא רקורסיבית
למה בדיוק הכוונה? תודה,
On what conditions do you return a solid value / constant and stop calling your function recursively ?
The maximal points that a participant can achieve in a given time.
Isn't that what choose(m,t) should return?
Or maybe choose_mem should return the max points only if it was calculated before?