## 题目描述

You are attempting to learn to play a simple arcade dancing game. The game has 4 arrows set into a pad: Up, Left, Down, Right. While a song plays, you watch arrows rise on a screen, and when they hit the top, you have to hit the corresponding arrows on the pad. There is no penalty for stepping on an arrow without need, but note that merely standing on an arrow does not activate it; you must actually tap it with your foot. Many sequences in the game are very fast-paced, and require proper footwork if you don't want to tire yourself out. Write a program to determine the easiest way to execute a certain sequence of arrows.

We will work with a basic time unit of an eighth-note. At any given time, your left foot and right foot will each be on distinct arrows. Only one foot may perform an action (changing arrows and/or tapping) during any time unit; jumping is not allowed. Also, you must remain facing forward in order to see the screen. This puts limitations on which feet you can use to hit which arrows. Finally, hitting two arrows in a row with the same foot ("double-tapping") is exhausting, because you can't shift your weight onto that foot. Ideally, you want to alternate feet all the way through a string of consecutive arrows.

Performing an action with a foot costs 1 unit of energy if it did NOT perform an action in the previous time unit. If it did, then it costs 3 units if it doesn't change arrows, 5 units if it moves to an adjacent arrow, and 7 units if it moves directly across the pad (between Up and Down, or Left and Right).

Under normal circumstances, you can't put your left foot on Right, or your right foot on Left. However, you CAN do a temporary "crossover": if your left foot is on Up or Down, you can twist your hips and put your right foot on Left – but until your right foot moves away, you can't move your left to a different arrow. (Imagine the tangle your legs would get into if you tried!) Similarly, you can cross your left foot over/behind your right.

## 输入

You will be given multiple arrow sequences to provide foot guides for. Every sequence consists of a line containing from 1 to 70 characters, representing the arrow that must be hit at each time unit. The possible characters are U, L, D, and R, signifying the four arrows, or a period, indicating that no arrow need be hit. Assume that your left and right feet start on the Left and Right arrows for the first time unit of a sequence.

There are at most 100 sequences. Input is terminated by a line consisting of a single #.

## 输出

For each input sequence, output a string of the same length, indicating which foot should perform an action at each time step, or '.' if neither does. If there are multiple solutions that require minimal energy, any will do.

## 样例输入

```
LRLRLLLLRLRLRRRRLLRRLRLDU...D...UUUUDDDD
#
```

## 样例输出

```
LRLRLLLLRLRLRRRRLLRRLRLRL...R...LLLLRRRR
```

## 参考代码

```
#include <stdio.h>
char *B[] = {"LR","LU","LD","UR","UD","UL","RD","RU","DL","DU","DR"};
int t[200][22], prev[200][22];
stepcost(char x, char y)
{
if (x == y) return 3;
if (x == 'R' && y == 'L' || x == 'U' && y == 'D') return 7;
if (x == 'L' && y == 'R' || x == 'D' && y == 'U') return 7;
return 5;
}
cost(int s1, int s2, char m)
{
int p1 = s1%2, b1 = s1/2, p2 = s2%2, b2 = s2/2;
if (m == '.')
{
int a,b;
if (s1/2 == s2/2) return 0;
a = cost(s1,s2,'L');
b = cost(s1,s2,'R');
if (b<a) a = b;
b = cost(s1,s2,'U');
if (b<a) a = b;
b = cost(s1,s2,'D');
if (b<a) a = b;
return a;
}
if (p2 == 0)
{
// moving left foot
if (B[b2][0] != m) return 999999;
// have to end with foot in place
if (B[b2][1] == m) return 999999;
// other foot on the square
if (B[b1][1] == 'L' && B[b1][0] != m) return 999999;
// crossed over
if (B[b1][1] != B[b2][1]) return 999999;
// can't move other foot
if (p1 == 1) return 1;
// alternating feet
return stepcost(B[b1][0],m);
} else
{
if (B[b2][1] != m) return 999999;
// have to end with foot in place
if (B[b2][0] == m) return 999999;
// other foot on the square
if (B[b1][0] == 'R' && B[b1][1] != m) return 999999;
// crossed over
if (B[b1][0] != B[b2][0]) return 999999;
// can't move other foot
if (p1 == 0) return 1;
// alternating feet
return stepcost(B[b1][1],m);
}
}
char buf[10000];
int i,j,k,n;
dump(int j, int k)
{
int i;
if (j == 0) return 0;
for (i=0;i<22;i++)
{
if (t[j-1][i] + cost(i,k,buf[j-1]) == t[j][k])
{
dump(j-1,i);
if (cost(i,k,buf[j-1]) == 0) printf("."); else printf("%c","LR"[k%2]);
return 0;
}
}
}
main()
{
while (gets(buf) && *buf != '#')
{
n = strlen(buf);
for (i=0;i<=n;i++) for (j=0;j<22;j++) t[i][j] = 999999;
t[0][0] = t[0][1] = 0;
for (i=0;i<n;i++)
{
for (j=0;j<22;j++) for (k=0;k<22;k++)
{
if (t[i][j] == 999999) continue;
int c = cost(j,k,buf[i]);
if (t[i][j] + c < t[i+1][k])
{
t[i+1][k] = t[i][j] + c;
prev[i+1][k] = j;
0&&printf("step %d from %d %s to %d %s cost %d total %dn",
i,j%2,B[j/2],k%2,B[k/2],c,t[i+1][k]);
}
}
}
k = 0;
for (i=0;i<22;i++) if (t[n][i] < t[n][k]) k = i;
dump(n,k);
//printf(" %dn",t[n][k]);
printf("n",t[n][k]);
}
if (*buf != '#') printf("missing end delimitern");
}
```

## 解析

暂无