To find , solve . You can iterate: start from and keep incrementing while . The largest such is your tower height. Let .
Now count how many ways to assign colors to each level such that you use at most red blocks and at most green blocks, with exactly total blocks used. This is where the DP comes in.