Number of ways

1

5 votes
Open, Open, Open, Dynamic Programming, Algorithms, Easy, Introduction to Dynamic Programming 1
Problem

You are standing at a distance of X kilometers from your house. You can travel at most K kilometers in a single step.

Your task is to determine the total number of ways to reach your house.
As the number of ways can be large, print it modulo 109+7.

Note: You cannot take a step of 0 kilometers. This means that the steps should be positive integers.

Input format

  • First line: An integer T denoting the number of test cases
  • Each of the next T lines: contains two integers X and K

Output format
For each test case, print the number of ways modulo 109+7. The answer to each test case should come in a new line.

Constraints

1T105

1X104

1K102

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

For Test case 1 :

K=2 and X=3 , so she can reach in 3 ways

a 1,1,1 (taking all step of one)

b 1,2 (1st step one and 2nd as two)

c 2,1 (1st two and 2nd as one)

Editor Image

?