# UVa 707

##  Summary

A Dynamic Programming problem which requires some special care.

##  Explanation

We are told that there is a robber capable of moving one unit per time in a rectangular gridlike city. Furthermore, we are given subrectanges of the city that we know the robber was not in at different points in time. We have to determine where the robber could possibly be at each time slice in a given range.

Memoization is particularly well-suited for this problem. Maintain a 3 dimensional table indexed by width, height, and time holding 3 possible values, yes the robber could be there, no the robber cannot be there, and uncomputed. Initialize the table to uncomputed for all possible values. Then read the witness input and mark every rectangle given by them to vacant. Now we can use memoization to decide which paths lead to a valid city block after the time is over. Start from the time t, and work back to time 1. A given position (width,height,time) can be reached only if at least one of its at most 5 predeccesors can be reached $(width \pm 1, height \pm 1, time - 1)$ and (width,height,time - 1). Obviously, time = 1 is the base case for the recursion. Don't be greedy, explore all 5 options, even if the first one works, since we not only want to determine if the position is feasible, but also if it is unique.

After trying trying all paths starting at the end time, we can then perform the output. If there are no places at the finishing time where the robber can be, output that the robber must have escaped. Otherwise, for each time that there is only one position, output that position. Finally, if nothing was printed, output Nothing known.

##  Gotcha's

• Work back to foward in time, working forward to back will lead you astray.

##  Input

I/O taken from the UVa message board referenced at the bottom of this page.

5 5 3
2
1 1 1 4 4
2 2 2 5 5

5 5 3
2
1 1 1 4 5
2 2 1 5 5

10 1 10
1
1 2 1 10 1

10 1 5
3
1 2 1 10 1
3 1 1 2 1
3 4 1 10 1

10 1 5
3
1 2 1 10 1
4 1 1 2 1
4 4 1 10 1

100 100 100
0

1 1 3
0

1 1 1
1
1 1 1 1 1

0 0 0



##  Output

Robbery #1:
Nothing known.

Robbery #2:
The robber has escaped.

Robbery #3:
Time step 1: The robber has been at 1,1.

Robbery #4:
Time step 1: The robber has been at 1,1.
Time step 2: The robber has been at 2,1.
Time step 3: The robber has been at 3,1.

Robbery #5:
Time step 1: The robber has been at 1,1.
Time step 4: The robber has been at 3,1.

Robbery #6:
Nothing known.

Robbery #7:
Time step 1: The robber has been at 1,1.
Time step 2: The robber has been at 1,1.
Time step 3: The robber has been at 1,1.

Robbery #8:
The robber has escaped.



##  References

1. Forum post with useful help and sample I/O