#include <stdio.h>
#include <stdlib.h> #include <string.h> #include "iostream" #include "string" #include "queue" #include "algorithm" typedef long long LL; using namespace std; const int maxn = 505; int mp[maxn][maxn]; char fun[maxn][maxn]; int Next[4][2] = { {1,0},{0,-1},{0,1},{-1,0} }; char X[4] ; int sum = 0; struct point { int x, y; int f; }q[maxn*maxn]; void print1(int p) { sum++; if (p!=0) { print1(q[p].f); } // if (p != 0) // printf("%c",fun[q[p].x][q[p].y]); } void print(int p) { //sum++; if (p != 0) { print(q[p].f); } if (p != 0) printf("%c", fun[q[p].x][q[p].y]); } int main() { memset(mp, 0, sizeof(mp)); strcat(X, "DLRU"); int M, n; cin >> M >> n; for (int i = 0; i < M; i++)//输入 { getchar(); for (int j = 0; j < n; j++) { char m = getchar(); if (m != '0')mp[i][j] = 1; else mp[i][j] = 2; } } point m ; m.x = 0; m.y = 0; m.f = -1; mp[0][0] = 1; q[0] = m; int head=0, tail=1; while (head<=tail) { if (q[head].x == M-1&&q[head].y == n-1) { print1(head); cout << sum-1 << endl; print(head); cout << endl; } int x = q[head].x; int y = q[head].y; for (int i = 0; i < 4; i++) { int x1 = x + Next[i][0]; int y1 = y + Next[i][1]; if ((x1 >= 0) && (y1 >= 0 )&& (x1 < M)&&(y1 < n)&&(mp[x1][y1] == 2)) { fun[x1][y1] = X[i]; mp[x1][y1] = 1; q[tail].x = x1; q[tail].y = y1; q[tail].f = head; tail++; } } head++; } return 0; }