p2397_SpiderMan

来源:互联网 发布:7u分享网络是什么 编辑:程序博客网 时间:2024/05/14 12:14

 

Spiderman
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1032 Accepted: 364 Special Judge

Description

Stayingfit is important for every superhero, and Spiderman is no exception.Every day he undertakes a climbing exercise in which he climbs acertain height of a tall building, rests for a minute, then climbsagain, rests again, and so on. The exercise is described by a sequenceof heights d1, d2, d3, ... , dm telling how many meters he is to climbbefore the first break, before the second break, and so on. From anexercise perspective it does not really matter if he climbs up or downat the ith climbing stage, but it is practical that sometimes climbs upand sometimes climbs down, so that he both starts and finishes atstreet level. Obviously, he can never be below street level! Also, hewould like to climb as short a building as possible (he does not liketo admit it, but he is actually afraid of heights). The building mustbe at least 2 meters higher than the highest point his feet reachduring the workout.

He wants your help in determining when he should go up and when heshould go down. The answer must be legal: it must start and end atstreet level (0 meters above ground) and it may never go below streetlevel. Among the legal solutions he wants one that minimizes therequired building height. When looking for a solution, you may notreorder distances.

If the distances are 20 20 20 20, he can either climb up, up, down,down or up, down, up, down. Both are legal, but the second one isbetter (in fact optimal) because it only requires a building of height22, whereas the first one requires a building of height 42. If thedistances are 3 2 5 3 1 2, an optimal legal solution is to go up, up,down, up, down, down. Note that for some distance sequences there is nolegal solution at all (e.g., for 3 4 2 1 6 4 5).

Input

Thefirst line of the input contains an integer N giving the number of testcases. The following 2N lines specify the test cases, two lines pertest case: the first line gives a positive integer M, which is thenumber of heights, and the following line contains the M positiveinteger heights. For any test case, the total distance climbed (the sumof the heights in that test case) is at most 1000.

Output

Foreach test case a single line should be output. This line should eitherbe the string "IMPOSSIBLE" if no legal solution exists, or it should bea string of length M, containing only the characters "U" and "D", wherethe ith character indicates if Spiderman should climb up or down at theith stage. If there are several different legal and optimal solutions,output one of them (it does not matter which one as long as it isoptimal).

Sample Input

3
4
20 20 20 20
6
3 2 5 3 1 2
7
3 4 2 1 6 4 5

Sample Output

UDUD 
UUDUDD
IMPOSSIBLE

Source

Tehran 2003 Preliminary

设mn[i][j]为走完第i个在j高度时候达到的最小的最高值是什么
在构造最优解的时候出现了下述错误,找了很久。
原因:
1.逻辑不清;
2.查代码看的不全面,要注意这种关系。
3.样例出现了毛病,应该多测几组,各个情况应予以考虑。