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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
#include <cassert>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

char ver[10][10], hol[10][10];
const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const char dir[] = {'U','R','D','L'};

void input() {
  scanf("%s", hol[1]+1);
  rep(i,4) {
    scanf("%s", ver[i+1]+1);
    scanf("%s", hol[i+2]+1);
  }
  rep(i,8) rep(j,8) {
    if (hol[i][j] == '1') hol[i][j] = 1;
    else hol[i][j] = 0;
    if (ver[i][j] == '1') ver[i][j] = 1;
    else ver[i][j] = 0;
  }
  // rep(i,8) {
  //   putchar(' ');
  //   rep(j,8) printf("%2d", hol[i][j]); puts("");
  //   rep(j,8) printf("%2d", ver[i][j]); puts("");
  // }
}

bool is_end(int x, int y, int d) {
  return (x == 0 && y == 1 && d == 0) ||
      (x == 1 && y == 1 && d == 3);
}

void update(int &x, int &y, int &d) {
  const int bx = x, by = y, bd = d;
  switch (d) {
    case 0: {
      if (hol[y][x]) d = 3;
      else if (ver[y-1][x+1]) --y;
      else if (hol[y][x+1]) { ++x; --y; d = 1; }
      break;
    }
    case 1: {
      if (ver[y][x+1]) d = 0;
      else if (hol[y+1][x+1]) ++x;
      else if (ver[y+1][x+1]) { ++x; ++y; d = 2; }
      break;
    }
    case 2: {
      if (hol[y+1][x]) d = 1;
      else if (ver[y+1][x]) ++y;
      else if (hol[y+1][x-1]) { --x; ++y; d = 3; }
      break;
    }
    case 3: {
      if (ver[y][x]) d = 2;
      else if (hol[y][x-1]) --x;
      else if (ver[y-1][x]) { --x; --y; d = 0; }
      break;
    }
  }
  if (bx == x && by == y && bd == d) {
    printf("%d %d %d\n", x, y, d);
    assert(false);
  }
}

void solve() {
  int x = 1, y = 0, d = 1;
  string ans = "R";
  do {
    // printf("%d,%d - %d : %s\n", x, y, d, ans.c_str());
    update(x, y, d);
    ans += dir[d];
  } while (!is_end(x,y,d));
  printf("%s\n", ans.c_str());
}

int main() {
  input();
  solve();
  return 0;
}

C++: #include<iostream>
using namespace std;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
char dc[]={'R','D','L','U'};
bool t[6][6][4];
int flg=0;
void init();
bool ck(int y,int x,int d){
	if(t[y][x][d]==1)return false;
	int ny=y+dy[d];
	int nx=x+dx[d];
	if(t[ny][nx][(d+2)%4]==1)return false;
	return true;
}
void rec(int y,int x,int d);
int main(){
	init();
	//cout<<"test"<<endl;
	for(int i=0;i<=3;i++){
		for(int j=1;j<=4;j++){
			cin>>t[i][j][1];
		}
		for(int j=0;j<=4;j++){
			cin>>t[i+1][j][0];
		}
	}
	for(int i=1;i<=4;i++)cin>>t[4][i][1];
	//cout<<"inputend"<<endl;
	rec(0,1,0);
	return 0;
}
void init(){
	for(int i=0;i<6;i++)
		for(int j=0;j<6;j++)
			for(int k=0;k<4;k++)
				t[i][j][k]=0;
}
void rec(int y,int x,int d){
	//cout<<y << " " <<x<<" "<<d<<endl;
	flg++;
	if(y==0&&x==0){
		cout<<endl;
		return;
	}
	
	int d1=(d+1)%4;
	int d2=(d+2)%4;
	int d3=(d+3)%4;
	if(ck(y,x,d1)){
		//cout<<dc[d1];
		rec(y+dy[d1],x+dx[d1],d1);
	}else if(ck(y,x,d)){
		cout<<dc[d];
		rec(y+dy[d],x+dx[d],d);
	}else if(ck(y,x,d3)){
		cout<<dc[d3];
		rec(y+dy[d3],x+dx[d3],d3);
	}else{
		cout<<dc[d2];
		rec(y+dy[d2],x+dx[d2],d2);
	}
}

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

int main() {
  int vx,vy,direction;
  string str;
  vx = 2;
  vy = 2;
  direction = 1;
  int ex[9][8]={0},ey[8][9]={0};
  for(int i=0;i<9;i++) {
    if((i == 0)||(i == 2)||(i == 4)||(i == 6)||(i == 8)) {
      //  cin >> ex[i/2][0] >> ex[i/2][1] >> ex[i/2][2] >> ex[i/2][3];
      cin >> str;
      ex[i/2+2][2] = atoi(str.substr(0,1).c_str());
      ex[i/2+2][3] = atoi(str.substr(1,1).c_str());
      ex[i/2+2][4] = atoi(str.substr(2,1).c_str());
      ex[i/2+2][5] = atoi(str.substr(3,1).c_str());
    }
    else {
      //  cin >> ey[0][(i-1)/2] >> ey[1][(i-1)/2] >> ey[2][(i-1)/2] >> ey[3][(i-1)/2] >> ey[4][(i-1)/2];
      cin >> str;
      ey[2][(i-1)/2+2] = atoi(str.substr(0,1).c_str());
      ey[3][(i-1)/2+2] = atoi(str.substr(1,1).c_str());
      ey[4][(i-1)/2+2] = atoi(str.substr(2,1).c_str());
      ey[5][(i-1)/2+2] = atoi(str.substr(3,1).c_str());
      ey[6][(i-1)/2+2] = atoi(str.substr(4,1).c_str());
    }
  }
  /*    for(int i=2;i<7;i++) {
      for(int j=2;j<6;j++) {
      cout << ex[i][j];
      }
      cout << endl;
      } */

  while(1) {
    if(direction == 1) {
      if(ey[vy-1][vx] == 1) {
	vy--;
	direction = 2;
	cout << "U";
      }
      else if(ex[vy][vx] == 1) {
	vx++;
	direction = 1;
	cout << "R";
      }
      else if(ey[vy][vx] == 1) {
	vy++;
	direction = 4;
	cout << "D";
      }
    }
    else if(direction == 2) {
      if(ex[vy][vx-1] == 1) {
	vx--;
	direction = 3;
	cout << "L";
      }
      else if(ey[vy-1][vx] == 1) {
	vy--;
	direction = 2;
	cout << "U";
      }
      else if(ex[vy][vx] == 1) {
	vx++;
	direction = 1;
	cout << "R";
      }
    }
    else if(direction == 3) {
      if(ey[vy][vx] == 1) {
	vy++;
	direction = 4;
	cout << "D";
      }
      else if(ex[vy][vx-1] == 1) {
	vx--;
	direction = 3;
	cout << "L";
      }
      else if(ey[vy-1][vx] == 1) {
	vy--;
	direction = 2;
	cout << "U";
      }
    }
    else if(direction == 4) {
      if(ey[vy][vx] == 1) {
	vx++;
	direction = 1;
	cout << "R";
      }
      else if(ey[vy][vx] == 1) {
	vy++;
	direction = 4;
	cout << "D";
      }
      else if(ex[vy][vx-1] == 1) {
	vx--;
	direction = 3;
	cout << "L";
      }
    }
  }
  cout << endl;
}