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

int main(){
	char WX[7][6],WY[6][7];
	for(int i=0;i<7;i++){
		for(int j=0;j<6;j++){
			WX[i][j] = 0;
			WY[j][i] = 0;
		}
	}
	for(int i=1;i<5;i++) cin >> WX[i][1];
	for(int i=1;i<6;i++) cin >> WY[1][i];
	for(int i=1;i<5;i++) cin >> WX[i][2];
	for(int i=1;i<6;i++) cin >> WY[2][i];
	for(int i=1;i<5;i++) cin >> WX[i][3];
	for(int i=1;i<6;i++) cin >> WY[3][i];
	for(int i=1;i<5;i++) cin >> WX[i][4];
	for(int i=1;i<6;i++) cin >> WY[4][i];
	for(int i=1;i<5;i++) cin >> WX[i][5];

	int NX = 1;
	int NY = 1;
	char s = 'R';
	while(1){
		if(s=='R'){
			if(WY[NY-1][NX]=='1'){ s = 'U'; NY--; cout << s;}
			else if(WX[NX][NY]=='1'){ NX++; cout << s;}
			else if(WY[NY][NX]=='1'){ s = 'D'; NY++; cout << s;}
			else s = 'L';
		}
		else if(s=='L'){
			if(WY[NY][NX]=='1'){ s = 'D'; NY++; cout << s;}
			else if(WX[NX-1][NY]=='1'){ NX--; cout << s;}
			else if(WY[NY-1][NX]=='1'){ s = 'U'; NY--; cout << s;}
			else s = 'R';
		}
		else if(s=='U'){
			if(WX[NX-1][NY]=='1'){ s = 'L'; NX--; cout << s;}
			else if(WY[NY-1][NX]=='1'){ NY--; cout << s;}
			else if(WX[NX][NY]=='1'){ s = 'R'; NX++; cout << s;}
			else s = 'D';
		}
		else if(s=='D'){
			if(WX[NX][NY]=='1'){ s = 'R'; NX++; cout << s;}
			else if(WY[NY][NX]=='1'){ NY++; cout << s;}
			else if(WX[NX-1][NY]=='1'){ s = 'L'; NX--; cout << s;}
			else s = 'U';
		}
		if(NX*NY==1) break;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
void righ(int x,int y);
void lef(int x,int y);
void up(int x,int y);
void down(int x,int y);
void serch(int x,int y,int then);
int main()
{
    for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
    cin>>Longitudinal[4];
    cout<<"R";
    serch(1,0,0);
}
void righ(int x,int y)
{
    if(x+1<5&&Longitudinal[y][x]=='1'){
        cout<<"R";
        serch(x+1,y,0);
    }
}
void lef(int x,int y)
{
    if(x-1>-1&&Longitudinal[y][x-1]=='1'){
        cout<<"L";
        serch(x-1,y,2);
    }
}
void up(int x,int y)
{
    if(y-1>-1&&side[y-1][x]=='1'){
        cout<<"U";
        serch(x,y-1,3);
    }
}
void down(int x,int y)
{
    if(y+1<5&&side[y][x]=='1'){
            cout<<"D";
            serch(x,y+1,1);
        }
}
void serch(int x,int y,int then)
{
    if(x==0&&y==0){
        cout<<endl;
        exit(0);
    }
    if(then==0){
        up(x,y);
        righ(x,y);
        down(x,y);
    }
    else if(then==1){
        righ(x,y);
        down(x,y);
        lef(x,y);
    }
    else if(then==2){
        down(x,y);
        lef(x,y);
        up(x,y);
    }
    else{
        lef(x,y);
        up(x,y);
        righ(x,y);
    }
}

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[5][5][4];
int flg=0;
void init();
bool ck(int y,int x,int d){
	if(t[y][x][d]==1)return true;
	int ny=y+dy[d];
	int nx=x+dx[d];
	if(t[ny][nx][(d+2)%4]==1)return true;
	return false; 
}
void rec(int y,int x,int d);
int main(){
	init();
	cout<<"test"<<endl;
	for(int i=0;i<=3;i++){
		for(int j=0;j<=3;j++){
			cin>>t[i][j][0];
		}
		for(int j=0;j<=4;j++){
			cin>>t[i][j][1];
		}
	}
	for(int i=0;i<=3;i++)cin>>t[4][i][0];
	cout<<"inputend"<<endl;
	rec(0,0,0);
	return 0;
}
void init(){
	for(int i=0;i<5;i++)
		for(int j=0;j<5;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&&flg>1){
		cout<<endl;
		return;
	}
	
	int d1=(d+1)%4;
	int d2=(d+2)%4;
	int d3=(d+3)%4;
	if(ck(y,x,d3)){
		cout<<dc[d3];
		rec(y+dy[d3],x+dx[d3],d3);
	}else if(ck(y,x,d)){
		cout<<dc[d];
		rec(y+dy[d],x+dx[d],d);
	}else if(ck(y,x,d1)){
		cout<<dc[d1];
		rec(y+dy[d1],x+dx[d1],d1);
	}else{
		cout<<dc[d2];
		rec(y+dy[d2],x+dx[d2],d2);
	}
}

C++: #include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

char lab[11][7];
string s;

void f(int i,int j){

	if(i==1 && j==1) return;
	else{

		string a="URDLURDLUR";
		int dx[]={0 ,-1,0,1, 0,-1,0};
	    int dy[]={-1, 0,0,0,-1, 0,0};

        rep(k,4){
		if(s[s.size()-1]==a[k]){

		if(lab[i+dx[k]][j+dy[k]]-'0'==1){
			s+=a[k+3];
			if(dx[k]==0 && dy[k]==0) f(i,j+1);  else f(i+2*dx[k],j+dy[k]);
		}
		else if(lab[i+dx[k+1]][j+dy[k+1]]-'0'==1){
			s+=a[k+4];
			if(dx[k+1]==0 && dy[k+1]==0) f(i,j+1);  else f(i+2*dx[k+1],j+dy[k+1]);
		}
		else if(lab[i+dx[k+2]][j+dy[k+2]]-'0'==1){
			s+=a[k+5];
			if(dx[k+2]==0 && dy[k+2]==0) f(i,j+1);  else f(i+2*dx[k+2],j+dy[k+2]);
		}
		else if(lab[i+dx[k+3]][j+dy[k+3]]-'0'==1){
			s+=a[k+6];
			if(dx[k+3]==0 && dy[k+3]==0) f(i,j+1);  else f(i+2*dx[k+3],j+dy[k+3]);
		}
		break;
		}
		}

	}

}

int main(){

	REP(i,1,9){
	if(i%2==1)
	REP(j,1,4) cin >> lab[i][j];
	else
	REP(k,1,5) cin >> lab[i][k];
	}

    s+='R';

   f(1,2);

   cout << s << endl;

   return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>
 
#define f first
#define s second
#define mp make_pair
 
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;
 
typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;
 
int kabe[5][5][5][5];
 
enum direct {
  RIGHT = 0,
  DOWN  = 1,
  LEFT  = 2,
  UP    = 3
};
 
const char *dstr = "RDLU";
 
const int dx[4] = { 1, 0,-1, 0};
const int dy[4] = { 0, 1, 0,-1};
 
#define D(d) (((d)+4)%4)
 
bool go(int x1, int y1, int x2, int y2){
  if(x2 < 0 || y2 < 0 || x2 >= 5 || y2 >= 5) return false;
  return kabe[x1][y1][x2][y2] == 1;
}
 
int main(){
  string str;
  REP(i,9){
    cin>>str;
    if(i%2 == 0){
      REP(j,4){
    int x = j;
    int y = i/2;
    if(str[j] == '1'){
      kabe[x][y][x+1][y] = kabe[x+1][y][x][y] = 1;
    }
      }
    }else{
      REP(j,5){
    int x = j;
    int y = i/2;
    if(str[j] == '1'){
      kabe[x][y][x][y+1] = kabe[x][y+1][x][y] = 1;
    }
      }
    }
  }
  int x = 0, y = 0;
  int d = RIGHT;
  while(x != 0 || y != 0 || d == RIGHT){
    d = D(d-1);
    while(!go(x,y,x+dx[d],y+dy[d])) d = D(d+1);
    putchar(dstr[d]);
    x += dx[d]; y += dy[d];
  }
  puts("");
  return 0;
}