The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 5 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Recently, Hogwarts School of Witchcraft and Wizardry has introduced a course on coumputer programming! As a result, many programming duels now take place in Hogwarts. Lucius Malfoy has challenged Harry Potter to one such programming duel.
The rules of the duel are as follows:
1) Malfoy chooses two integers N(>0) and K(>=0) and a sequence S of N positive integers.
2) Harry must find the number of distinct non-empty subsequences L of S such that no two integers in L have an absolute difference greater than K.
Since this number may be very large, Harry must report this number modulo (10^9+7).
Input will begin with an integer T, the total number of test cases. Description of T test cases follows.
Each test case is described by two lines of input.
The first line of each test case will consist of two space-seperated integers : N,K.
The second line will contain N space seperated integers : S[1],S[2], ... S[N].
For each test case output a single integer : The number that Harry must report to Malfoy.
1 T
1 N
0 K
1 S[i]
Input: 2 3 1 10 11 12 5 6 12 27 1 13 14 Output: 5 9
CASE 1 : Possible subsequences : (10), (11), (12), (10,11), (11,12).
CASE 2 : Possible subsequences : (12), (27), (1), (13), (14), (12,13), (12,14), (13,14), (12,13,14).
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll