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++: #define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

char tate[4][5];
char yoko[5][4];

void test(int x, int y, int j){
	//cout<<x<<" "<<y<<" "<<endl;
	int i;
	//cin>>i;
	if(j==0){                                  //右に動いた時
		if(x-1>=0 && tate[x-1][y]=='1'){       //行き止まり　上に
			cout<<"U";
			test(x-1, y, 1);
		}
		else if(y+1<5 && yoko[x][y]=='1'){     //右に行ける
			cout<<"R";
			test(x, y+1, 0);                   
		}
		else if(x+1<5 && tate[x][y]=='1'){     //行き止まり　下に
			cout<<"D";
			test(x+1, y, 3);    //下に
		}
	}
	else if(j==1){                             //上に動いた時
		if(y-1>=0 && yoko[x][y-1]=='1'){       //行き止まり　左に
			cout <<"L";
			test(x, y-1, 2);
		}
		else if(x-1>=0 && tate[x-1][y]=='1'){  //上に行ける
			cout <<"U";
			test(x-1, y, 1);
		}
		else if(y+1<5 && yoko[x][y]=='1'){     //行き止まり　右に
			cout <<"R";
			test(x, y+1, 0);
		}
	}
	else if(j==2){                             //左に動いた時
		if(x+1<5 && tate[x][y]=='1'){          //行き止まり　下に
			cout<<"D";
			test(x+1, y, 3);
		}
		else if(y-1>=0 && yoko[x][y-1]=='1'){  //左に行けるなら
			cout<<"L";
			test(x, y-1, 2);
		}
		else if(x-1>=0 && tate[x-1][y]=='1'){  //行き止まり　上に
			cout<<"U";
			test(x-1, y, 1);
		}
	}
	else if(j==3){                             //下に動いた時
		if(y+1<5 && yoko[x][y]=='1'){          //行き止まり　右に
			cout <<"R";
			test(x, y+1, 0);
		}
		else if(x+1<5 && tate[x][y]=='1'){     //下に行けるなら
			cout <<"D";
			test(x+1, y, 3);
		}
		else if(y-1>=0 && yoko[x][y-1]=='1'){  //行き止まり　左に
			cout <<"L";
			test(x, y-1, 2);
		}
	}
}

int main(){

	for(int i=0;i<4;i++){
		cin >> yoko[i][0] >> yoko[i][1] >> yoko[i][2] >> yoko[i][3];
		cin >> tate[i][0] >> tate[i][1] >> tate[i][2] >> tate[i][3] >> tate[i][4];
	}
	cin >> yoko[4][0] >> yoko[4][1] >> yoko[4][2] >> yoko[4][3];
	
	test(0, 0, 0);
	
	cout<<endl;
	
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
int gd(int d, vector<int> w){
	if(w[(d+1)%4]==1) return (d+1)%4;
	else if(w[d]==1) return d;
	else if(w[(d+3)%4]==1) return (d+3)%4;
	else return (d+2)%4;
};
signed main(){
	char buf[256];
	vector<vector<vector<int>>> rms(5,vector<vector<int>>(5, vector<int>(4,0)));
	for(int i=0;i<9;i++){
		scanf("%s",buf);
		if(i%2==0){
			for(int j=0;j<4;j++){
				if(buf[j]=='1'){
					rms[i/2][j][0] = 1;
					rms[i/2][j+1][2] = 1;
				}
			}
		}else{
			for(int j=0;j<5;j++){
				if(buf[j]=='1'){
					rms[i/2][j][3] = 1;
					rms[i/2+1][j][1] = 1;
				}
			}
		}
	}
	int x=0,y=0,d=0;
	while(true){
		d = gd(d,rms[y][x]);
		if(d==0){cout<<"R"; x++;}
		else if(d==1){cout<<"U"; y--;}
		else if(d==2){cout<<"L"; x--;}
		else {cout<<"D"; y++;}
		if(x==0&&y==0) break;
	}
	cout << endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int xdir[4] = {1, 0, -1, 0} ,ydir[4] = {0, 1, 0, -1};
char dir[4] = {'R', 'D', 'L', 'U'};

int main()
{
  int l, x, y, d;
  string str;
  bool a[11][11][11][11]; // current pos[h][w], next pos[h][w]

  while(cin>>str){
    l = str.size()+1;
    y = 1;
    fill(&a[0][0][0][0], &a[l+1][0][0][0], false);

    for(int i = 1; i < l; ++i)
      if(str[i-1] == '1')
	a[0][i-1][0][i] = a[0][i][0][i-1] = true;

    for(int i = 1; i <= 8; ++i){
      cin >> str;
      if(i%2){
	for(int j = 0; j < l; ++j)
	  if(str[j] == '1') 
	    a[y-1][j][y][j] = a[y][j][y-1][j] = true;
      } else {
	for(int j = 1; j < l; ++j)
	  if(str[j-1] == '1')
	    a[y][j-1][y][j] = a[y][j][y][j-1] = true;
	y++;
      }
    }

    x = y = d = 0;
    do {
      int dx = x+xdir[d], dy = y+ydir[d];
      if(0 > dx || dx >= l || 0 > dy || dy >= l || !a[y][x][dy][dx]){
	int d1 = (d+1)%4, d2 = (d+3)%4, d3 = (d+2)%4;
	dx = x+xdir[d1]; dy = y+ydir[d1];
	if(0 > dx || dx >= l || 0 > dy || dy >= l || !a[y][x][dy][dx]){
	  dx = x+xdir[d2]; dy = y+ydir[d2];
	  if(0 > dx || dx >= l || 0 > dy || dy >= l || !a[y][x][dy][dx]){
	    dx = x+xdir[d3]; dy = y+ydir[d3];
	    d = d3;
	  } else {
	    d = d2;
	  }
	} else {
	  d = d1;
	}
      }      

      // for(int i = 0; i < 4; ++i){
      // int dx = x+xdir[(d+i)%4], dy = y+ydir[(d+i)%4];


      // if(0 <= dx && dx < l && 0 <= dy && dy < l && a[y][x][dy][dx]){
      // cout << dir[(d+i)%4];
      cout << dir[d];
      // cout<<": ("<<x<<", "<<y<<") -> ("<<dx<<", "<<dy<<")"<<endl;  
	  a[y][x][dy][dx] = false;
	  x = dx;
	  y = dy;
	  // d = (d+i)%4;
	  // break;
	  // 	}
	// }
    } while(x+y != 0);

    cout << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct P {
  bool r, d, l, u;
  P() { r = d = l = u = false; }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  P p[5][5];
  for (int i = 0; i < 9; i++) {
    cin >> s;
    if (i & 1) {
      for (int j = 0; j < 5; j++) {
        if (s[j] == '1') p[i / 2][j].d = p[i / 2 + 1][j].u = true;
      }
    } else {
      for (int j = 0; j < 4; j++) {
        if (s[j] == '1') p[i / 2][j].r = p[i / 2][j + 1].l = true;
      }
    }
  }
  string ans = "R";
  int y = 0, x = 1, d = 0;
  while (!(y == 0 && x == 0)) {
    if (d == 0) {
      if (p[y][x].u) y--, d = 3, ans += 'U';
      else if (p[y][x].r) x++, d = 0, ans += 'R';
      else if (p[y][x].d) y++, d = 1, ans += 'D';
      else x--, d = 2, ans += 'L';
    } else if (d == 1) {
      if (p[y][x].r) x++, d = 0, ans += 'R';
      else if (p[y][x].d) y++, d = 1, ans += 'D';
      else if (p[y][x].l) x--, d = 2, ans += 'L';
      else y--, d = 3, ans += 'U';
    } else if (d == 2) {
      if (p[y][x].d) y++, d = 1, ans += 'D';
      else if (p[y][x].l) x--, d = 2, ans += 'L';
      else if (p[y][x].u) y--, d = 3, ans += 'U';
      else x++, d = 0, ans += 'R';
    } else {
      if (p[y][x].l) x--, d = 2, ans += 'L';
      else if (p[y][x].u) y--, d = 3, ans += 'U';
      else if (p[y][x].r) x++, d = 0, ans += 'R';
      else y++, d = 1, ans += 'D';
    }
  }
  cout << ans << endl;

  return 0;
}