Social distancing

5

2 votes
Counting and Arrangements, Dynamic Programming, Algorithms, Basics of Greedy Algorithms
Problem

There are m persons and n chairs. Each person needs to maintain social distance between themselves and the person they are sitting next to. Therefore, once a person sits, the person who sits next to them sits at a distance that is in multiples of the integer k.

Your task is to find the total number of arrangements possible so that all the people can be seated. Print your answer modulo 109+7.

Notes

  • All the people must get a chair to sit on
  • Two arrangements are different either if the state of a chair is different in both cases or if two different people are seated on it. For example, for n=10 chairs, m=2 persons, and k=2, if the first person sits at the 2nd position, then the second person can sit only at the 4th, 6th, 8th, or 10th position.

Input format
The first line contains an integer t representing the number of test cases.

Each of the next t lines contains three integers n, m, and k.

Output format

Print ti ntegers where the ith integer is the total number of arrangements for the ithtest case.

Constraints

1t105

1n,m,k106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case, total 4 arrangements are possible. Let 5 chairs are numbered from 1 to 5, then arrangements for 2 persons are {1,3}, {1,5}, {2,4} and {3, 5}.

In the second test case, only 1 arrangement is possible.

Editor Image

?