APAT question: Class photograph. Can someone explain the logic to implement?

There are “b” boys and “g” girls in a class. Today is the day of their class photograph. The photographer loves having different arrangements for a photograph. He decides that the photo would look awesome if there are atmost n1 adjacent boys and atmost adjacent n2 girls lined up together. if there are more than n1 boys, or more than n2 girls standing together(successively one after another), then the photograph will not look awesome.

So, find the number of ways in which the photographer can arrange b boys and g girls so that the photograph looks awesome.

Input Format:
One line containing four integers - b , g , n1 , n2 .

Constraints:
1<=b,g<=1000
1 ≤ n1,n2 ≤ 20

Output Format:
Output a single i.e the no.of arrangements modulo 10^9 + 7

Sample Input:
1 2 5 1
Sample Output:
1
Explanation:
Example case 1. “GBG” is the only awesome arrangement.

you can make two call at a particular state …
make a boy stand in the row if already the no of boys standing adjcent to each other are less than given figure
same goes for the girls
Refer the code for the same

1 Like

It will give a TLE I guess