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 field[6][6]={0};
  string s;
  for(int i=0; i<5; i++){
    cin >>s;
    for(int j=0; j<s.size(); j++){
      if(s[j] == '1'){
	field[i][j+1]+=4;
	field[i+1][j+1]+=1;
      }
    }
    cin >>s;
    if(i!=4){
      for(int j=0; j<s.size(); j++){
	if(s[j] == '1'){
	  field[i+1][j]+=2;
	  field[i+1][j+1]+=8;
	}
      }
    }
  }
  int d = 2,x = 0,y = 1;
  for(;;){
    if(d == 1){
      if(field[x][y]&2){
	cout <<"U";
	if(field[x][y]&1)d = 8;
	else x--; 
      }
      else{d = 2;y++;}
    }
    else if(d == 2){
      if(field[x][y]&4){
	cout <<"R";
	if(field[x][y]&2) d = 1;
	else y++;
      }
      else{d = 4;x++;}
    }
    else if(d == 4){
      if(field[x][y]&8){
	cout <<"D";
	if(field[x][y]&4) d = 2;
	else x++;
      }
      else{d = 8;y--;}
    }
    else if(d == 8){
      if(field[x][y]&1){
	cout <<"L";
	if(field[x][y]&8) d = 4;
	else y--;
      }
      else{d = 1;x--;}
    }
    if(x == 0 && y == 1) break;
  }
  cout <<endl;
  return 0;
}

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

#define LEFT 0
#define UP   1
#define RIGHT 2
#define DOWN 3

#define MIN(X,Y) ((X<Y)?X:Y)
#define MAX(X,Y) ((X>Y)?X:Y)

bool map[5][5][5][5];
int direction=RIGHT;
int pos[2]={0,0};
char nul[5000];


void read(void)
{
	for(int y=0;y<4;y++)
	{
		for(int x=0;x<4;x++)
			map[x][y][x+1][y] = (getchar()-'0' == 1);
		gets(nul);
		for(int x=0;x<5;x++)
			map[x][y][x][y+1] = (getchar()-'0' == 1);
		gets(nul);
	}
	for(int x=0;x<4;x++)
		map[x][4][x+1][4] = (getchar()-'0' == 1);
	return;
}

bool isenable(int x, int y)
{
	return ((0<=x)&&(x<=4))&&((0<=y)&&(y<=4));
}

bool isconnect(int dir)
{
	int x=pos[0], y=pos[1];
	switch(dir) {
		case LEFT:   x--;
			     break;
		case UP:     y--;
			     break;
		case RIGHT:  x++;
			     break;
		case DOWN:   y++;
			     break;
	}
	return (isenable(x,y)&&(map[MIN(pos[0],x)][MIN(pos[1],y)][MAX(pos[0],x)][MAX(pos[1],y)]));
}
void step(int dir)
{
	switch(dir) {
		case LEFT:   pos[0]--; std::cout << "L" << std::flush; direction=LEFT;
			     break;
		case UP:     pos[1]--; std::cout << "U" << std::flush; direction=UP;
			     break;
		case RIGHT:  pos[0]++; std::cout << "R" << std::flush; direction=RIGHT;
			     break;
		case DOWN:   pos[1]++; std::cout << "D" << std::flush; direction=DOWN;
			     break;
	}
	return;
}

void move(void)
{
	do {
		if(isconnect((direction+LEFT-1+4)%4))
			step((direction+LEFT-1+4)%4);
		else if(isconnect((direction+UP-1+4)%4))
			step((direction+UP-1+4)%4);
		else if(isconnect((direction+RIGHT-1+4)%4))
			step((direction+RIGHT-1+4)%4);
		//else
			//std::cerr << "error" << std::endl;

		//std::cerr << "(x,y):" << pos[0] << "," << pos[1] << std::endl;
	}while(!(pos[0]==0 && pos[1]==0));

	std::cout << std::endl;
	return;
}

int main(void)
{
	for(int i=0; i<5; i++)
		for(int j=0; j<5; j++)
			for(int k=0; j<5; j++)
				for(int l=0; j<5; j++)
					map[i][j][k][l] = false;

	read();
	move();
}

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<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N=6;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
const string op="RDLU";
enum{RIGHT=0,DOWN,LEFT,UP};
int m[N][N];
bool e[N][N][N];


string solve(){
  int y=0,x=1,r=RIGHT;
  string ret="";
  do{
    bool a=true;
    if (!e[y][x][(r+1)%4])r=(r+1)%4;
    while(e[y][x][r])ret+=op[r],r=(r+3)%4;
    if (e[y][x][(r+1)%4])ret+=op[r];
    y+=dy[r];
    x+=dx[r];
  }while(y != 0 || x != 1);
  return ret;
}

main(){
  rep(i,N)rep(j,N)rep(k,4)e[i][j][k]=false;
  rep(i,5){
    string tmp;
    cin>>tmp;
    rep(j,4)if (tmp[j] == '1')e[i][j+1][DOWN]=e[i+1][j+1][UP]=true;
    if (i == 4)break;
    cin>>tmp;
    rep(j,5)if (tmp[j] == '1')e[i+1][j][RIGHT]=e[i+1][j+1][LEFT]=true;
  }
  cout << solve() << endl;
}