Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 478D Red Green Towers - Base Cases

Starting point

Before building any levels, you've used 00 red blocks in exactly one way (by doing nothing). dp[0][0]=1dp[0][0] = 1. For any j>0j > 0: dp[0][j]=0dp[0][j] = 0. You can't use red blocks without building any levels.

From here, iterate through levels i=1,2,,hi = 1, 2, \dots, h and apply the transition. After processing all levels, sum dp[h][j]dp[h][j] for every valid jj to get the total number of ways to color the tower.