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>
using namespace std;

int main(){
  int f,xyf;
  char h[5][4],v[4][5];
  int x,y;
  cin>>h[0];
  for(int i=0;i<4;i++){
    cin>>v[i];
    cin>>h[i+1];
  }
  f=xyf=1;
  y=0;
  x=1;cout<<"R";
  while(x!=0||y!=0){
    if(f==1){
      if(xyf==1){
	if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;xyf*=-1;
	}
	else if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";
	}
	else if(v[y][x]=='0') xyf*=-1;
	else{
	  y++;f*=-1;cout<<"D";
	}
      }
      else{
	if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;
	}
	else if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";
	}
	else if(v[y][x]=='0') xyf*=-1;
	else{
	  y++;cout<<"D";f*=-1;xyf*=-1;
	}
      }
    }
    else{
      if(xyf==1){
	if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";f*=-1;
	}
	else if(y<4&&v[y][x]=='1'){
	  y++;cout<<"D";
	}
	else if(h[y][x-1]=='0') xyf*=-1;
	else{
	  x--;cout<<"L";f*=-1;xyf*=-1;
	}
      }
      else{
	if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";f*=-1;
	}
	else if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";
	}
	else if(h[y][x]=='0') xyf*=-1;
	else{
	  x++;cout<<"R";f*=-1;xyf*=-1;
	}
      }
    }
  }
  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<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			if(-1<i&&i<ysize&&-1<j&&j<xsize){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<ysize&&-1<j-1&&j-1<xsize){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<ysize-1&&-1<j&&j<xsize){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<ysize-1&&-1<j&&j<xsize){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

void 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};
	while(1){
		for(int i=0;i<4;i++){
			if(x==0 && y==0 && (((v+loop[i])%4)==2 || ((v+loop[i])%4==1))){
				return;
			}
			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.eof()!=true;i++){
		cin>>tmp;
		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;
	}*/
	solve();
	cout<<endl;
	
	return 0;
	
}

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

struct P{
	int x,y;
	P(int x,int y) : x(x), y(y){}; 
	P(){}
};
bool operator < (const P &a,const P &b){
	if( a.x != b.x ) return a.x < b.x;
	return a.y < b.y;
}


string dd = "RDLU";

P g[5][5][4];

map<P,string> memo;
string dfs(P p,int d,string s,string rs){
	//cout << p.x << " " << p.y <<" " << d<< endl;
	if( memo.count(p) ){
		string r = memo[p];
		reverse(r.begin(),r.end());
		cout << s + r << endl;
		exit(0);
	}
	memo[p] = rs;

	for(int i = 0 ; i < 4 ; i++){
		if( g[p.y][p.x][(i+d)%4].x != -1){
			dfs(g[p.y][p.x][(i+d)%4],(i+d)%4,s+dd[(i+d)%4],rs+dd[(i+d+2)%4]);
			
		}
	}

}
int main(){
	for(int i = 0 ; i < 5 ; i++)
		for(int j = 0 ; j < 5 ; j++)
			for(int k = 0 ; k < 4 ; k++)
				g[i][j][k] = P(-1,-1);
	
	for(int i = 0 ; i < 9 ; i++){
		string s;
		cin >> s;
		//cout << s << endl;
		if( i % 2 ){
			int y = i / 2;
			for(int j = 0 ; j < 5 ; j++)
				if( s[j] == '1' ){
					//cout << j << " " << y+1 << "<" << endl;
					g[y][j][1] = P(j,y+1);
					g[y+1][j][3] = P(j,y);
				}			
		}else{
			int y = i / 2;
			for(int j = 0 ; j < 4 ; j++)
				if( s[j] == '1' ){
					g[y][j][0] = P(j+1,y);
					g[y][j+1][2] = P(j,y);
				}
		}
		
	}
	dfs(P(0,0),0,"","");
}