I’m working on a problem right now and am having a bit of trouble.
Here’s the question:

I’ve gotten to a point in the program where I can generate all possible rows for a given length and can calculate the number of other rows that align with each other. I can calculate base cases fairly quick, but my program is very naive and calculates walls recursively, with each of the possible rows as bases of a wall and which builds walls recursively on each possible leaf combination. As you can imaging, this isn’t very efficient, and for anything above height 6 my program takes a very, very long time.
I’ve seen this problem on the forum from an earlier, but my question wasn’t really answered and I couldn’t reply to it. Help/ideas is/are greatly appreciated.
Oh, and I’m writing the program in c++.
EDIT: I’m having a lot of trouble, could someone look at my code and suggest improvements?
EDIT2: Ok, I have an answer now, I get 806844323190414 possible walls for a 48×10 inch wall. If anyone wants, I can post post my methodology/code, or just general advice.
Observe that when you have built k rows, it’s only the topmost (k th) row that restricts what the next row may look like. Consider the question “when I have built k rows and the topmost row looks like x, in how many ways can I build the remaining wall?” This can be solved by asking the same question for all compatible ways of making the k+1 th row and summing the results. The answer to the entire problem is the sum of the answers to the questions “When I have built 1 row and the topmost row looks like x“, for all possible ways of building the first row. This problem can be solved using memoization or dynamic programming.