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<bitset>
#include<string>
#include<algorithm>
#define UP_DIRECTION 3
#define RIGHT_DIRECTION 2
#define DOWN_DIRECTION 1
#define LEFT_DIRECTION 0
using namespace std;
int dy[]={0,1,0,-1},dx[]={-1,0,1,0};
int main(){
    bitset<4>Square[5][5];
    string Wall[9];
    char For_Output[]="LDRU";
    for(int i=0;i<9;i++)cin>>Wall[i];

    for(int i=0;i<9;i+=2){
        Wall[i]="0"+Wall[i]+"0";
        for(int j=0;j<5;j++){
            Square[i/2][j][LEFT_DIRECTION]=(Wall[i][j]-'0');
            Square[i/2][j][RIGHT_DIRECTION]=(Wall[i][j+1]-'0');
        }
    }

    for(int i=1;i<9;i+=2){
        for(int j=0;j<5;j++){
            Square[i/2][j][DOWN_DIRECTION]=(Wall[i][j]-'0');
            Square[i/2+1][j][UP_DIRECTION]=(Wall[i][j]-'0');
        }
    }
    int Direction=RIGHT_DIRECTION;
    int y=0,x=0;

    do{
        if(Square[y][x][(Direction+1)%4])
            Direction++;

        else if(!Square[y][x][Direction])
            Direction--;

        if(Direction>3)Direction=0;
        if(Direction<0)Direction=3;

        y+=dy[Direction];
        x+=dx[Direction];
        cout<<For_Output[Direction];
    }while(y!=0||x!=0);
    cout<<endl;
}

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[dir][0],y+delta[dir][1])) {
            if(can(v, x,y, x+delta[left][0],y+delta[left][1])) {
                dir = left;
            }
            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++: #define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

char tate[4][5];
char yoko[5][4];
bool flag = false;

void test(int x, int y, int j){
	//cout<<x<<" "<<y<<" "<<endl;
	int i;
	//cin>>i;
	if(x==0&&y==0){
		cout<<endl;
		return;
	}

	if(j==0){                                  //右に動いた時
		if(x-1>=0 && tate[x-1][y]=='1'){       //行き止まり　上に
			cout<<"U";
			test(x-1, y, 1);
		}
		else if(y+1<5 && yoko[x][y]=='1'){     //右に行ける
			cout<<"R";
			test(x, y+1, 0);                   
		}
		else if(/*x+1<5 && */tate[x][y]=='1'){     //行き止まり　下に
			cout<<"D";
			test(x+1, y, 3);    //下に
		}
	}
	else if(j==1){                             //上に動いた時
		if(y-1>=0 && yoko[x][y-1]=='1'){       //行き止まり　左に
			cout <<"L";
			test(x, y-1, 2);
		}
		else if(x-1>=0 && tate[x-1][y]=='1'){  //上に行ける
			cout <<"U";
			test(x-1, y, 1);
		}
		else if(/* y+1<5 && */ yoko[x][y]=='1'){     //行き止まり　右に
			cout <<"R";
			test(x, y+1, 0);
		}
	}
	else if(j==2){                             //左に動いた時
		if(x+1<5 && tate[x][y]=='1'){          //行き止まり　下に
			cout<<"D";
			test(x+1, y, 3);
		}
		else if(y-1>=0 && yoko[x][y-1]=='1'){  //左に行けるなら
			cout<<"L";
			test(x, y-1, 2);
		}
		else if(x-1>=0 && tate[x-1][y]=='1'){  //行き止まり　上に
			cout<<"U";
			test(x-1, y, 1);
		}
	}
	else if(j==3){                             //下に動いた時
		if(y+1<5 && yoko[x][y]=='1'){          //行き止まり　右に
			cout <<"R";
			test(x, y+1, 0);
		}
		else if(x+1<5 && tate[x][y]=='1'){     //下に行けるなら
			cout <<"D";
			test(x+1, y, 3);
		}
		else if(y-1>=0 && yoko[x][y-1]=='1'){  //行き止まり　左に
			cout <<"L";
			test(x, y-1, 2);
		}
	}
}

int main(){

	for(int i=0;i<4;i++){
		cin >> yoko[i][0] >> yoko[i][1] >> yoko[i][2] >> yoko[i][3];
		cin >> tate[i][0] >> tate[i][1] >> tate[i][2] >> tate[i][3] >> tate[i][4];
	}
	cin >> yoko[4][0] >> yoko[4][1] >> yoko[4][2] >> yoko[4][3];
	
	cout << "R";
	test(0, 1, 0);
	
	return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>  
#include<map>
#include<set>
using namespace std;

int main(){
	bool f[13][13]={};
	int TT[15][15]={};
	string p,q;
	for(int i=1;i<=4;i++){
		cin>>p>>q;
		for(int j=0;j<p.size();j++)
			if(p[j]=='1')f[2*i-1][j+1]=1;
		for(int j=0;j<q.size();j++)
			if(q[j]=='1')f[i*2][j+1]=1;
	}
	cin>>p;
		for(int j=0;j<p.size();j++)
			if(p[j]=='1')f[9][j+1]=1;
	/*for(int i=0;i<=10;i++){
		for(int j=0;j<=5;j++)
			cout<<f[i][j];
		cout<<endl;
	}*/
	int x=1,y=1;
	char z='R';int v=0;
	while(1){
		if(z=='R'){
			if(f[y-1][x]){
				cout<<"U";z='U';y-=2;
			}
			else if(f[y][x]){
				cout<<"R";z='R';x++;
			}
			else if(f[y+1][x]){
				cout<<"D";z='D';y+=2;
			}
			else{
				cout<<"L";z='L';x--;
			}


		}
		else if(z=='L'){
			if(f[y+1][x]){
				cout<<"D";z='D';y+=2;
			}
			else if(f[y][x-1]){
				cout<<"L";z='L';x--;
			}
			else if(f[y-1][x]){
				cout<<"U";z='U';y-=2;
			}
			else{
				cout<<"R";z='R';x++;
			}
		}

		else if(z=='U'){
			if(f[y][x-1]){
				cout<<"L";z='L';x--;
			}
			else if(f[y-1][x]){
				cout<<"U";z='U';y-=2;
			}
			else if(f[y][x]){
				cout<<"R";z='R';x++;
			}
			else{
				cout<<"D";z='D';y+=2;
			}
		}
		else if(z=='D'){
			if(f[y][x]){
				cout<<"R";z='R';x++;
			}
			else if(f[y+1][x]){
				cout<<"D";z='D';y+=2;
			}
			else if(f[y][x-1]){
				cout<<"L";z='L';x--;
			}
			else{
				cout<<"U";z='U';y-=2;
			}
		}
		if(x==1&&y==1)break;
		v++;
		//if(v>30)break;
		//cout<<x<<" "<<y<<"#"<<v<<endl;
		TT[y][x]=v;
	}/*
	for(int i=0;i<=10;i++){
		for(int j=0;j<=5;j++)
			cout<<TT[i][j];
		cout<<endl;
	}
	*/

	cout<<endl;
	return 0;
}