Unable to understand the base cases for this recurrence relation: DPn = DPn-1 + DPn-3 + DPn-4

41 Views Asked by At

I read the following here
Sub-problem: DPn be the number of ways to write N as the sum of 1, 3, and 4.
Finding recurrence: Consider one possible solution, n = x1 + x2 + ... xn. If the last number is 1, the sum of the remaining numbers should be n - 1. So, number of sums that end with 1 is equal to DPn-1.. Take other cases into account where the last number is 3 and 4. The final recurrence would be:

DPn = DPn-1 + DPn-3 + DPn-4.

Base cases: DP0 = DP1 = DP2 = 1, and DP3 = 2.

My Problem - I do not at all understand the base cases, I did get the recurrence relation though. Am not getting as to what DP0 = DP1 = DP2 = 1 really mean here.

1

There are 1 best solutions below

1
On BEST ANSWER

How many ways can you write each of $0,1,2,3$ as a sum of $1,3,4$?

  • For $n=0$, the empty sum is the only way.
  • For $n=1$, $1$ is the only way.
  • For $n=2$, $1 + 1$ is the only way.
  • For $n=3$, $3$ and $1 + 1 + 1$ are the only two ways.