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'};

string res;
void touch_wall (int row, int col, int dir, int hand )
{
	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;
	res = "";
	while (!(row == 1 && col == 0 && (dir == LEFT ) ) ){
		touch_wall (row, col, dir, hand );
		if ((1<<hand & grid[row][col] ) == 0 ){	// 右手の壁がなくなった、なくなった方向に回転
			dir = hand;
		}else
		if ((1<<dir & grid[row][col] ) != 0 ){	
			while ((1<<dir & grid[row][col] ) != 0 ){// 右手の壁があったとしても前に進めない
				dir = (4+dir-1)%4;
				touch_wall (row, col, dir, hand );
			} // 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 );
	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<string>
#include<vector>
using namespace std;

static const int X = 11, Y = 11;
static const int DIR = 4;
static const string dirchar= "RDLU";
static const int dirx[DIR] = {1,0,-1,0}, diry[DIR] = {0,1,0,-1};

int main(){
	int field[X][Y] = {0};
	string s;
	int x,y;
	y=0;
	while( getline(cin,s) ){
		for(x=0;x<s.size();++x)field[x*2+1][y+1] = s[x]-'0';
		y++;
	}
	for(y=1;y<Y;y+=2) for(x=1;x<X;x+=2) if(field[x][y])field[x+1][y] = 1;
	for(y=2;y<Y;y+=2) for(x=1;x<X;x+=2)
		if(field[x][y]){
			field[x][y+1] = 1;
			field[x][y-1] = 1;
		}
	vector<int> ans;
	x=y=1;
	int dir=0;
	while(true){
		for(int i=0; i<DIR; ++i){
			const int tdir = (dir+DIR-1+i)%DIR;
			if( field[x + dirx[tdir]][y + diry[tdir]] ){
				x += dirx[tdir]*2;
				y += diry[tdir]*2;
				ans.push_back(tdir);
				dir = tdir;
				break;
			}
		}
		if( x==1 && y==1 )break;
	}
	for(int i=0;i<ans.size();++i)cout << dirchar[ans[i]];
	cout << endl;
	return 0;
}

C++: #include <iostream>
#include <sstream>

using namespace std;

char perm_angle[4] = {'R','U','L','D'};
int grid[5][5][4] = {0};

void move(int,int,char);
char det_angle(int,int,char);

int main(){
	int flag;
	for(int i=0;i<9;i++){
		if(i%2 == 0){
			for(int j=0;j<4;j++){
				fscanf(stdin,"%1d",&flag);
				//cout << flag;
				if(flag == 1){
					//cout << "+";
					grid[i/2][j][0]  = 1; //R
					grid[i/2][j+1][2]= 1; //L
				}
			}
		}
		else{
			for(int j=0;j<5;j++){
				fscanf(stdin,"%1d",&flag); 
				//cout << flag;
				if(flag == 1){
					//cout << "-";
					grid[i/2][j][3]  = 1; //D
					grid[i/2+1][j][1]= 1; //U
				}
			}
			
		}
		//cout << endl;
	}
	/*for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			cout << 100*i+j;
			for(int k=0;k<4;k++){
				cout <<  " "  << grid[i][j][k];
			}
			cout << endl;
		}
	}*/
//	if(fscanf(stdin,"%1d",&map[i][j]) != EOF){

	//int x = 0, y = 0;
	//char angle = 'R';
	/*do{
		move(x,y,det_angle(x,y,angle))
	}while(x == 0 && y == 0);*/
	cout << 'R';
	move(0,1,'R');
}

void move(int x,int y,char angle){
	if(x == 0 && y== 0)
		exit(1);
	
	cout << angle;
	
	if(angle == 'R'){
		++y;
	}
	else if(angle == 'U'){
		--x;
	}
	else if(angle == 'L'){
		--y;
	}
	else if(angle == 'D'){
		++x;
	}
	//cout << "test" << x <<" " << y;
	move(x,y,det_angle(x,y,angle));
	//cout << angle << endl; 
}

char det_angle(int x,int y,char angle){
	
	//cout << x << y << " " << angle << endl;
	int start;
	if(angle == 'R'){
		start = 5;
	}
	else if(angle == 'U'){
		start = 6;
	}
	else if(angle == 'L'){
		start = 7;	
	}
	else if(angle == 'D'){
		start = 4;
	}
	//cout << start << endl;
	for(int i = start;start - i < 4 ;--i){
		if(grid[x][y][i%4] == 1){
			//cout << "kettei" << i <<endl ;
			return perm_angle[i%4];
		}
	}
	return 'Z';
}