A planned trip

4

4 votes
Probability spaces, Dynamic Programming, Algorithms
Problem

Bob decided to go on a trip. There are total N kids on the trip. There are 3 types of toys - 'Type-1', 'Type-2', and 'Type-3' available for the distribution among N kids. Each of the kids is asked, what kind of toy he prefers from the current lot. If the kid does not like any toy from the current lot, then he or she would get a toy among the remaining types with equal probability.

Bob wants a 'Type-1' toy. He knows that there are A 'Type-1' toys, B 'Type-2' toys, and C 'Type-3' toys. He noticed that he is at Kth position in the queue. He also knows that a random kid prefers 'Type-1' toys with probability P1% and 'Type-2' toys with probability P2%. Obviously, if a kid does not prefer 'Type-1' and 'Type-2' toys, he or she prefers 'Type-3' toys.

Now he wants to know, what is his chance to get a 'Type-1' toy.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains an integer N denoting the total number of kids.
  • The second line of each test case contains three space-separated integers denoting the values of A, B, and C.
  • The third line of each test case contains an integer K denoting the position of Lucky on the queue.
  • The fourth line of each test case contains two space-separated integers denoting the values of P1 and P2.

Output format

For each test case, print the Lucky’s probability to get a 'Type-1' toy in a new line. Print your answer modulo 1e9+7.

Constraints

1T100A,B,C2001NA+B+C1KN0P1,P2100 (P1+P2100)

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

For the first testcase, the number of Type-1 toys are 0, thus Lucky can't get a Type-1 toy.

For the second testcase, the number of Type-1 toys are 4. The Lucky is on 4-th position in the queue, thus there is 100% chance that Lucky get a Type-1 toy.

For the third testcase, 

  • When the first kid choses Type-1 toy, then the probability for Lucky to get Type-1 toy is 30/1000=0.
  • When the first kid choses Type-3 toy, then the probability for Lucky to get Type-1 toy is 40/1001=40/100.
  • When the first kid choses Type-2 toy, then the probability for Lucky to get Type-1 toy is 30/100((1/2)0+(1/2)1)=15/100.

Thus there is 40/100+15/100=55/100 chance for Lucky to get a Type-1 toy.

Editor Image

?