It's actually easier than you think. :O)
[edit]
Er, I made an error in my assessment...
I'll take a look at it again later
(sorry)
[/edit]
The paper only gave you very simple examples, but here's one that makes you think a little more.
CBBXBBC
For simplicity each letter in the example represents a entire distinct grouping --
not just a single letter. If all we have is X (which may be "HELLO", for example) then it is not a 'block palindrome'.
break down
Our first step is to break that down into its individual pieces:
C B B X B B C
(Again, that might actually be "HI BYE BYE HELLO BYE BYE HI".
Obviously, I'm not limiting it to ten letters -- that is a limitation on input, not the algorithm.)
Since we have been able to break it down into more than one grouping then we know it is definitely a 'block palindrome'.
the question
Now, pay attention to what is being asked:
[How many] different ways the input can be grouped... |
A particularly important fact here is that you cannot change the palindrome-ness of the thing at this point. We are only interested in groupings.
groupings
Adjacent groupings can be paired (or concatenated) into larger groupings. This is our clue.
If you represent each potential pairing as (paired, not paired) you reduce it to a simple binary sequence:
C B B X 000
C B B+X 001
C B+B X 010
C B+B+X 011
C+B B X 100
C+B B+X 101
C+B+B X 110
C+B+B+X 111
1. Notice that the left and right sides are the same, so we can write
B+X instead of
B+X+B here.
2. Notice also that the all-bits-set sequence is specifically excluded from the block palindrome's list of correct groupings. So the last one must be excluded.
putting it together
Hopefully, you should now be able to both count (requires only some math) and produce (requires a loop) every possible grouping.
Part c requires a little bit of thinking as well...
Hope this helps.