Example 2 : Count of different ways to express N

TopicDifficultyCompanies
Dynamic Programming
EASY

Given N, write a program to count the number of ways to express N as sum of 1, 3 and 4.

Example 1

Input: N = 4
Output: 4
Explanation: 1+1+1+1
1+3
3+1
4

Example 2

Input: N = 5 
Output: 6
Explanation: 1 + 1 + 1 + 1 + 1
1 + 4
4 + 1
1 + 1 + 3
1 + 3 + 1
3 + 1 + 1

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.