AlgoFrames

Ways to make a total from 1, 3 and 4

Standard · Write code · about 10 min

Count the ordered ways to write n as a sum of the numbers 1, 3 and 4. The order counts: 1 + 3 and 3 + 1 are different ways.

For n = 0 the empty sum is the one way.

Example 1

Input:

[5]

Output:

6

Example 2

Input:

[4]

Output:

4

1+1+1+1, 1+3, 3+1, 4.

Constraints

  • 0 ≤ n ≤ 40
  • The answer fits in a 32-bit signed integer

Learn the idea first: Tabulation: filling the table bottom-up, a visual lesson.

More Tabulation: filling the table bottom-up problems