Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var points [5][5][4]bool

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for i := 0; i < 9; i++ {
		y := i/2
		if i%2 == 0 {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][1], points[y][k+1][3] = true, true
				}
			}
		} else {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][2], points[y+1][k][0] = true, true
				}
			}
		}
	}
	x := 1
	y := 0
	dir := 1
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	ds := "URDL"
	fmt.Printf("%s", string(ds[dir]))
	for !(x == 0 && y == 0) {
		if points[y][x][(dir+3)%4] {
			dir = (dir+3)%4
		} else if points[y][x][dir] {

		} else if points[y][x][(dir+1)%4] {
			dir = (dir+1)%4
		} else {
			dir = (dir+2)%4
		}
		x += dx[dir]
		y += dy[dir]
		fmt.Printf("%s", string(ds[dir]))
	}
	fmt.Println()
}

C++: #include <iostream>
#include <string>
#include <cstring>
using namespace std;

int map[10][5];
bool used[10][5];

bool f = true;
string S = "LURD";
void dfs( int r, int c, int a, int o )
{
    used[r][c] = true;
    if ( o ) {
        cout << S[a];
    }

    if ( !f && r == 0 && c == 0 ) {
        cout << endl;
        return;
    }

    if ( f ) {
        if ( a == 0 ) {
            if ( c == 0 || !map[r][c-1] ) {
                if ( !used[r][c-1] ) {
                    dfs( r-1, c, 1, 1 );
                } else {
                    f = false;
                    dfs( r, c, a, 0 );
                }
            } else if ( map[r][c-1] ) {
                if ( !used[r][c-1] ) {
                    dfs( r, c-1, 0, 1 );
                } else {
                    f = false;
                    dfs( r, c, a, 0 );
                }
            }
        } else if ( a == 1 ) {
            if ( r == 1 || !map[r-2][c] ) {
                if ( !used[r-1][c] ) {
                    dfs( r-1, c, 2, 1 );
                } else {
                    f = false;
                    dfs( r, c, a, 0 );
                }
            } else if ( map[r-2][c] ) {
                if ( !used[r-2][c] ) {
                    dfs( r-2, c, 1, 1 );
                } else {
                    f = false;
                    dfs( r, c, a, 0 );
                }
            }
        } else if ( a == 2 ) {
            if ( c == 3 || !map[r][c+1] ) {
                if ( !used[r+1][c+1] ) {
                    dfs( r+1, c+1, 3, 1 );
                } else {
                    f = false;
                    dfs( r, c, a, 0 );
                }
            } else if ( map[r][c+1] ) {
                if ( !used[r][c+1] ) {
                    dfs( r, c+1, 2, 1 );
                } else {
                    f = false;
                    dfs( r, c, a, 0 );
                }
            }
        } else if ( a == 3 ) {
            if ( c == 7 || !map[r+2][c] ) {
                if ( !used[r+1][c-1] ) {
                    dfs( r+1, c-1, 0, 1 );
                } else {
                    f = false;
                    dfs( r, c, a, 0 );
                }
            } else if ( map[r+2][c] ) {
                if ( !used[r+2][c] ) {
                    dfs( r+2, c, 3, 1 );
                } else {
                    f = false;
                    dfs( r, c, a, 0 );
                }
            }
        }
    } else {
        if ( a == 0 ) {
            if ( c == 0 || !map[r][c-1] ) {
                dfs( r+1, c, 3, 1 );
            } else if ( map[r][c-1] ) {
                dfs( r, c-1, 0, 1 );
            }
        } else if ( a == 1 ) {
            if ( r == 1 || !map[r-2][c] ) {
                dfs( r-1, c-1, 0, 1 );
            } else if ( map[r-2][c] ) {
                dfs( r-2, c, 1, 1 );
            }
        } else if ( a == 2 ) {
            if ( c == 3 || !map[r][c+1] ) {
                dfs( r-1, c+1, 1, 1 );
            } else if ( map[r][c+1] ) {
                dfs( r, c+1, 2, 1 );
            }
        } else if ( a == 3 ) {
            if ( r == 7 || !map[r+2][c] ) {
                dfs( r+1, c, 2, 1 );
            } else if ( map[r+2][c] ) {
                dfs( r+2, c, 3, 1 );
            }
        }
    }
}

int main( void )
{
    for ( int i = 0; i < 9; i++ ) {
        string line;
        cin >> line;
        for ( int j = 0; j < (i%2==0?4:5); j++ ) {
            map[i][j] = (int)(line[j] - '0');
        }
    }

    dfs( 0, 0, 2, 1 );

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
const int dy[] = {0,1, 0,-1};
const int dx[] = {1,0,-1, 0};
const int DY[4][4] = {{-1,0, 1,0},{1,2, 1,0},{ 1, 0,-1,0},{-1,-2,-1,0}};
const int DX[4][4] = {{ 1,2, 1,0},{1,0,-1,0},{-1,-2,-1,0},{-1, 0, 1,0}};
const int chdir[] = {3,0,1,2};
const string Dir = "URDLURDL";
ll grid[10][10];
// u = 1,r = 2, d = 4, l = 8
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vary(char,v,5,0);
  rep(i,9){
    if(i % 2){
      rep(j,5){
        cin >> v[j];
        v[j] -= '0';
        grid[j*2][i] = v[j];
      }
    }
    else{
      rep(j,4){
        cin >> v[j];
        v[j] -= '0';
        grid[j*2+1][i] = v[j];
      }
    }
  }
  ll x = 1,y = 0,c = 0,dir = 0;
  cout << "R";
  while(1){
    if(x == 1 && y == 0 && c) break;
    rep(i,4){
      ll nx = x + (DX[dir][i]),ny = y + (DY[dir][i]);
      if(value(nx,ny,10,10) && grid[nx][ny]){
        x = nx,y = ny;
        cout << Dir[dir+i];
        dir += chdir[i];
        dir %= 4;
        break;
      }
    }
    ++c;
    if(c > 100) break;
  }
  cout << endl;
//   rep(i,10){
//     rep(j,10){
//       scout(3) << grid[j][i];
//     }
//     cout << endl;
//   }
  return 0;
}

C++: #include <stdio.h>
char RideBack[9][9],T[6],ans[4]={'L','U','R','D'};int a[4][2]={-1,0,0,-1,1,0,0,1};bool OK=true;
void dfs(int x, int y, int w, int deep) {if (deep) printf("%c",ans[w]);if (!x && !y && deep) OK=false;for (int j=(w+3)&3;OK;j=(j+1)&3) {int n_x=x+a[j][0],n_y=y+a[j][1];if (n_x>=0 && n_x<9 && n_y>=0 && n_y<9 && RideBack[n_y][n_x]=='1') dfs(x+a[j][0]*2,y+a[j][1]*2,j,deep+1);}}
int main() {int i,j,k;for (i=0;i<9;i++) {scanf("%s",&T);if (i&1) for (k=0,j=0;j<5;RideBack[i][k]=T[j++],k+=2); else for (k=1,j=0;j<4;RideBack[i][k]=T[j++],k+=2);}dfs(0,0,1,0);puts("");return 0;}