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 <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0
#define TOP 0
#define RIGHT 1
#define BOTTOM 2
#define LEFT 3
#define DEBUG2 0
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.Path_on_a_Grid";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}
int grid[10][10];
const int dr[] = {-1, 0, 1, 0 };
const int dc[] = { 0, 1, 0,-1 };
const char Dir[] = { 'U','R','D','L'};

void touch_wall (int row, int col, int dir, int hand, string & res )
{
	if ((1<<hand & grid[row][col] ) != 0 )
		res += Dir[dir];	
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	memset (grid, 0, sizeof (grid ) );
/*
	rep (j, 5 ){
		grid[0][j] |= 1<<TOP;
		grid[5][j] |= 1<<BOTTOM;
	} // end rep
	rep (i, 6 ){
		grid[i][0] |= 1<<LEFT;
		grid[i][4] |= 1<<RIGHT;
	} // end rep
*/
	for (int i = 1; i <= 9; i++ ){
		string s = "";
		cin >> s;
		rep (j, s.length() ){
			if (i % 2 != 0 ){
				if (s[j] == '1' ){
					grid[i/2][j] |= 1<<BOTTOM;
					grid[(i+1)/2][j] |= 1<<TOP;
				} // end if
			}else{
				if (s[j] == '1' ){
					if (j == 0 ){
						grid[i/2][j] |= 1<<LEFT;
					}else{
						grid[i/2][j] |= 1<<LEFT;
						grid[i/2][j-1] |= 1<<RIGHT;
					} // end if
				} // end if
			} // end if
		} // end rep
	} // end for
/*
	rep (i, 6 ){
		rep (j, 5 ){
			cout << setw(2) << grid[i][j];
		} // end rep
		cout << endl;
	} // end rep
*/
	int row = 0, col = 0, dir = RIGHT;
	int hand = (dir+1)%4;
	string res = "";
	while (!(row == 1 && col == 0 && (dir == LEFT ) ) ){
		touch_wall (row, col, dir, hand, res );
		if ((1<<hand & grid[row][col] ) == 0 ){	// 右手の壁がなくなった
			dir = hand;
			while ((1<<dir & grid[row][col] ) != 0 ){	// 進行方向に壁がある
				dir = (4+dir-1)%4;
			} // end while
		}else
		if ((1<<dir & grid[row][col] ) != 0 ){	// 右手の壁があったとしても前に進めない
			dir = (4+dir - 1)%4;
			touch_wall (row, col, dir, hand, res );
			while ((1<<dir & grid[row][col] ) != 0 ){
				dir = (4+dir-1)%4;
				touch_wall (row, col, dir, hand, res );
			} // end while
		} // end if
		row = row + dr[dir];
		col = col + dc[dir];
		hand = (dir+1)%4;
#if DEBUG2
		cout << '(' << row << ',' << col << ')' << " dir: " << dir << endl;
#endif
	} // end while
	touch_wall (row, col, dir, hand, res );

	cout << res << endl;

#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <utility>

using namespace std;

typedef pair<int, int> Point;

int pack(int x, int y) {
    return x*5+y;
}

Point unpack(int p) {
    return make_pair(p/5, p%5);
}

bool can(const vector<vector<int> > &v, int x1, int y1, int x2, int y2) {
    if(x1 < 0 || y1 < 0 || x1 >= 5 || y1 >= 5) return false;
    if(x2 < 0 || y2 < 0 || x2 >= 5 || y2 >= 5) return false;
    return v[pack(x1,y1)][pack(x2,y2)];
}

int main() {
    vector<vector<int> > v(30, vector<int>(30, 0));
    for(int i = 0; i < 9; ++i) {
        string str;
        cin >> str;
        for(int j = 0; j < str.size(); ++j) {
            if(i % 2 == 0) v[pack(j, i/2)][pack(j+1, i/2)] = v[pack(j+1,i/2)][pack(j,i/2)] = str[j]-'0';
            else v[pack(j, i/2)][pack(j, i/2+1)] = v[pack(j,i/2+1)][pack(j,i/2)] = str[j]-'0';
        }
    }

    const char *dirchar = "RDLU";
    const int delta[][2] = {
        {1, 0}, {0, 1}, {-1, 0}, {0, -1}
    };
    int x = 0, y = 0;
    int dir = 0;
    while(true) {
        cout << dirchar[dir];
        x += delta[dir][0];
        y += delta[dir][1];
        if(x == 0 && y == 0) break;

        int left = (dir+3)%4;
        int right = (dir+1)%4;
        if(can(v, x,y, x+delta[left][0],y+delta[left][1])) {
            dir = left;
        }
        else if(can(v, x,y, x+delta[dir][0],y+delta[dir][1])) {
            dir = dir;
        }
        else if(can(v, x,y, x+delta[right][0],y+delta[right][1])) {
            dir = right;
        }
        else dir = (dir+2)%4;
    }
    cout << endl;
    return 0;
}

C++: #include<string>
#include<vector>
#include<iostream>
using namespace std;
bool map[20][20][4];
vector< string > maphor,mapver;
int xsize,ysize;
void init(){
for(int i=0;i<20;i++){
for(int j=0;j<20;j++){
for(int k=0;k<4;k++){
map[i][j][k]=0;
}
}
}
}
void setmap(){
for(int i=0;i<20;i++){
for(int j=0;j<20;j++){
if(-1<i&&i<maphor.size()&&-1<j&&j<maphor[0].size()){
if(maphor[i][j]=='1'){
map[i][j][0]=1;
}
}
if(-1<i&&i<maphor.size()&&-1<j-1&&j-1<maphor[0].size()){
if(maphor[i][j-1]=='1'){
map[i][j][2]=1;
}
}
if(-1<i&&i<mapver.size()&&-1<j&&j<mapver[0].size()){
if(mapver[i][j]=='1'){
map[i][j][3]=1;
}
}
if(-1<i-1&&i-1<mapver.size()&&-1<j&&j<mapver[0].size()){
if(mapver[i-1][j]=='1'){
map[i][j][1]=1;
}
}
}
}
}
int solve(){
int x=0,y=0;
int v=0;
string vec="RULD";
int loop[4]={1,0,3,2};
int vx[4]={1,0,-1,0};
int vy[4]={0,-1,0,1};
int count=0;
while(1){
count++;
if(count>100)return -1;
for(int i=0;i<5;i++){
if(i==4)return -1;
if(x==0
&& y==0
&&(((v+loop[i])%4)==2)){
return 0;
}
if(map[y][x][(v+loop[i])%4]==1){
v+=loop[i];
v=v%4;
x+=vx[v];
y+=vy[v];
cout<<vec[v];
break;
}
}
}
}
int main(){
string tmp;
for(int i=0;cin>>tmp;i++){
if(i%2==0){
maphor.push_back(tmp);
}else{
mapver.push_back(tmp);
}
}
xsize=maphor[0].size()+1;
ysize=mapver.size()+1;
init();setmap();
/*
for(int i=0;i<xsize;i++){
for(int j=0;j<ysize;j++){
for(int k=0;k<4;k++){
cout<<map[i][j][k];
}
cout<<" ";
}
cout<<endl;
}
*/
if(solve()==-1)return -1;
cout<<endl;
return 0;
}