πŸ—οΈ Ξ˜ΟΟ΅Ξ·Ξ Ξ±Ο„Ο€πŸš§ (under construction)

Programming Team
You are managing a team of programmers for n weeks. Each week you need to assign this group a job. There are two types of jobs, divided between β€œhigh-stress” and β€œlow-stress” jobs, given as arrays H, L where H[i] and L[i] are the expected earnings from taking a high stress job or a low stress job in week i respectively. However, high stress job requires preparation, and so if a high stress job is assigned to the team in week i, then they cannot work on any job in week i βˆ’ 1. On the other hand, a low stress job may be taken in week i regardless of what job has been assigned in the previous week. Your job as a manager is to assign the team a job (or not) each week given the arrays H, L, in such a way that the expected earnings of the team is maximized.
  • Derive the Bellman equation for a dynamic programming solution value. Clearly define all the variables in the Bellman equation and explain your solution.
  • Analyze the time and space complexity of the dynamic programming algorithm. (We did not ask you for the algorithm explicitly but you can still explain based on how the DP table is filled.)
Romeo and Juliet

Juliet has a secret to tell Romeo. However, every message that Juliet sends to Romeo needs to be examined by Capulet, Juliet's father. So Juliet decides to encrypt the message such that Capulet cannot understand easily. To simplify the problem, suppose there are only three letters in Juliet's alphabet Ξ£={a,b,c}. Juliet defines a mapping f:Ξ£β†’{0,1}*, where f(a)=0,f(b)=01,f(c)=11 . Suppose Juliet wants to send a message m∈{a,b,c}k. She sends the encrypted message f(m)=f(m1)∘f(m2)∘...∘f(mk) , where mi is the i th character of m, and ∘ means concatenation.

  1. Given f(m)=1101100110001110, how many possible messages are there, and what are they? (No justification required)
  2. Design a dynamic programming algorithm using memoization technique that decrypts any encrypted message s sent by Juliet. Your algorithm should return the original message m where f(m)=s. If the pre-image fβˆ’1(s) does not exist, return JUNK. Sometimes, Juliet sends meaningless junk to confuse her father.
  3. What is the time and space complexity of your algorithm? Briefly explain why.
  4. Consider Ξ£={a,b,c,d}, and the mapping f:Ξ£β†’{0,1}* is now f(a)=0,f(b)=01,f(c)=011,f(d)=1110. Is there a greedy algorithm to decrypt messages encrypted by this mapping? Briefly explain why.
Mario and Bowser

Bowser, a monster and a talented singer, is kidnapped by Princess Peach. Mario, who bought a ticket to Bowser's concert, is going to rescue Bowser. You are given a mΓ—n grid M. Mario starts from the top-left corner M[1,1], and Bowser is locked in the bottom-right corner M[m,n]. Mario has an initial health value. At each step, Mario can choose to move either right or down one slot. In each slot, there is either a Goomba or a mushroom. For simplicity, a Goomba is represented by a negative integer that reduces Mario's health, and a mushroom is represented by a positive integer that increases Mario's health. Mario dies if his health drops to 0 or below. Note that there is mushroom or Goomba in the top-left and bottom-right corner, too. For example, M=

βˆ’2βˆ’31βˆ’4βˆ’2331βˆ’5

When Mario starts from the top-left corner, he needs at least initial health 3 such that he will not die immediately. When Mario rescue's Bowser in the bottom-right corner, Mario needs to take the βˆ’5 damage first and not die before he can rescue Bowser.

  • In the example above, what is the minimum health Mario can start with such that he can rescue Bowser? And what is the path that Mario should follow? You can use a string RDRD to denote that Mario moves right, then down, then right, then down. No justification required.
  • Design a dynamic programming algorithm using bottom-up technique that works for a general mΓ—n grid M to determine the minimum initial health Mario can have such that he can rescue Bowser. Mario has to start with at least 1 health before he arrives at M[1,1]. You also need to (in the same algorithm or in a helper algorithm) output the string in {R,D}m+nβˆ’2 that indicates the path to rescue Bowser.
  • What is the time and space complexity of your algorithm(s)? Briefly explain why.