Victor's Various Adventures - Victor Counts Marbles

View as PDF

Submit solution


Points: 7
Time limit: 3.0s
Memory limit: 256M

Author:
Problem types

This is problem 2 of the Victor's Various Adventures problem set.

Victor is doing a question on his Data Management homework, but he isn't sure if he has the right answer. The question is as follows:

Given a row of M slots, where, in each slot a Black or White marble can be placed. Note that marbles of the same color are identical to each other.

Count the total number of placements where no more than R of the same-colored marbles next to each other.

Will you help him find the right answer?

Input Specification

The first and only line of input contains the space-separated integers M (2 \le M \le 16) and R (2 \le R \le M).

Output Specification

Output the correct answer on one line.

Sample Input 1

4 2

Sample Output 1

10

Explanation for Sample Output 1

The total number of possible arrangements (without the restriction) are: (B is for Black, and W is for White)

BBBB
BBBW
BBWB
BBWW
BWBB
BWBW
BWWB
BWWW
WBBB
WBBW
WBWB
WBWW
WWBB
WWBW
WWWB
WWWW

Once we remove the ones that do not meet the condition, the remaining are:

BBWB
BBWW
BWBB
BWBW
BWWB
WBBW
WBWB
WBWW
WWBB
WWBW

Comments

There are no comments at the moment.