#include using namespace std; constexpr int K = 1000; constexpr std::array DX = {1, -1, 0, 0}; constexpr std::array DY = {0, 0, 1, -1}; constexpr std::array DC = {'R', 'L', 'D', 'U'}; template bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int H, W, p; cin >> H >> W >> p; vector> B(H, vector(W - 1, 1)); vector> C(H - 1, vector(W, 1)); double T = pow(static_cast(p) / 100, 2); vector>> P(H, vector>(W, nullopt)); vector> Q(H, vector(W, 1 << 30)); for (int k = 0; k < K; k++) { for (auto&& e : P) { fill(e.begin(), e.end(), nullopt); } for (auto&& e : Q) { fill(e.begin(), e.end(), 1 << 30); } Q[0][0] = 0; priority_queue>, vector>>, greater>>> que; que.emplace(0, make_pair(0, 0)); while (!que.empty()) { const auto [d, pxy] = que.top(); que.pop(); const int y = pxy.first; const int x = pxy.second; if (Q[y][x] < d) continue; for (int i = 0; i < 4; i++) { const int ny = y + DY[i]; const int nx = x + DX[i]; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (i <= 1 && B[ny][min(x, nx)] <= T) continue; if (2 <= i && C[min(y, ny)][nx] <= T) continue; if (P[ny][nx]) continue; P[ny][nx] = DC[i]; double w = i <= 1 ? B[ny][min(x, nx)] : C[min(y, ny)][nx]; if (w == 100) { w = 0; } else { w = 1 - w; } if (chmin(Q[ny][nx], Q[y][x] + w)) { que.emplace(Q[ny][nx], make_pair(ny, nx)); } } } bool is_ok = true; string res = ""; int y = H - 1, x = W - 1; while (y != 0 || x != 0) { if (!P[y][x].has_value()) { is_ok = false; break; } res += P[y][x].value(); for (int i = 0; i < 4; i++) { if (DC[i] == P[y][x].value()) { y -= DY[i]; x -= DX[i]; break; } } } if (is_ok) reverse(res.begin(), res.end()); if (!is_ok) { for (auto&& e : B) { fill(e.begin(), e.end(), 0); } for (auto&& e : C) { fill(e.begin(), e.end(), 0); } k--; continue; } cout << res << endl; int r; cin >> r; if (r == -1) break; y = 0, x = 0; for (int i = 0; i <= r; i++) { int py = y, px = x, d = 0; for (int j = 0; j < 4; j++) { if (DC[j] == res[i]) { d = j; y += DY[j]; x += DX[j]; if (i < r && j < 2) { B[y][min(x, px)] = 100; } else if (i < r && j >= 2) { C[min(y, py)][x] = 100; } break; } } if (i == r) { if (d < 2) { if (B[y][min(x, px)] <= 1.0) B[y][min(x, px)] *= static_cast(p) / 100; } else { if (C[min(y, py)][x] <= 1.0) C[min(y, py)][x] *= static_cast(p) / 100; } } } } return 0; }