UCV2013E - Greedy Walking
Reginald is an N-dimensional traveler who wants to return to Filipistonia's Kingdom. He has an Obsessive-compulsive disorder in the way he travels so he can only do it following particular rules:
- Every step is exactly one unit long.
- He only moves in one dimension at a time.
- He only travels along the positive direction for each dimension.
For example, when traveling on a two-dimensional place. He can travel along either the X or the Y axis at any given time, but never on both at the same time. Moreover, since he only travels along the positive direction and every step is one unit long, his only possible moves are (+1, 0) and (0, +1).
As you can see, he is a Greedy Walker: once he makes a decision he assumes it is the correct and he never goes back.
Given a starting position in an N-dimensional space (x1i, x2i, ... ,xni) your task is to count the number of different travels he can make to position (x1f, x2f, ... , xnf) modulo 1000000007.
The input contains several test cases, each one corresponding to a single travel. Each test case consists of a single line with one integer (1 <= N <= 50) followed by two lines each one with N integers, first line will be initial position and second line will be target position.
You can assume that 0 <= xki <= x1f <= 500 for all k, 1 <= k <= N and Sum(xki-xkf) <= 500.
The end of input is indicated by a test case with N = 0.
For each travel output a single line with one integer, the number of different travels that exist from the initial position to the final position modulo 1000000007.
0 0 0 0
1 2 3 4
1 2 3 4 5
8 5 6 4 8
0 0 0 0 0
100 100 100 100 100
0 Output: 35
my 100th on spoj.. :)
@BroadSword there is only one way to get from a point to itself...
If initial and target positions are same..the result should be 0 or 1?
@SITH: Your program generates no output... I catched an exception:
I dont why I am getting WA again and again...@Hector could you explain to me why this is happening? Submission id 9708968