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<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<20;i++){
		for(int j=0;j<20;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			if(-1<i&&i<maphor.size()&&-1<j&&j<maphor[0].size()){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<maphor.size()&&-1<j-1&&j-1<maphor[0].size()){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

int 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};
	int count=0;
	while(1){
		count++;
		if(count>100)return -1;
		for(int i=0;i<5;i++){
			if(i==4)return -1;
			if(map[y][x][(v+loop[i])%4]==1){
				v=(v+loop[i])%4;
				x+=vx[v];
				y+=vy[v];
				cout<<vec[v];
				break;
			}
			if(x==0&& y==0){
				return 0;
			}
		}
	}
}

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;
	}
	*/
	if(solve()==-1)return -1;
	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
			step((direction+DOWN-1+4)%4);

		//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++: #include <cstdio>
#include <string>
#include <iostream>
using namespace std;

string str[3000];
int len;
int fie[3001][3001];
int m;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
char s[4]={'R','D','L','U'};
int main(void){
	int n=0;
	while(cin >> str[n])n++;
	m=str[0].size();
	for(int i=0;i<n;i++){
		for(int j=0;j<str[i].size();j++){
			if(str[i][j]=='1'){
				if(i%2==0)fie[j*2+2][i+1]=1;
				if(i%2==1)fie[j*2+1][i+1]=1;
			}
		}
	}
	int x=2,y=0,dir=0;
	while(1){
		int nx=x+dx[(dir+1)%4],ny=y+dy[(dir+1)%4];
		if(nx>=0 && nx<=m*2+2 && ny>=0 && ny<=n+1){
			if(fie[nx][ny]==1)printf("%c",s[dir]);
		}
		nx=x+dx[dir],ny=y+dy[dir];
		if(nx>=0 && nx<=m*2+2 && ny>=0 && ny<=n+1){
			if(fie[nx][ny]==0){
				x+=dx[dir]*2;
				y+=dy[dir]*2;
				if(fie[x+dx[(dir+1)%4]][y+dy[(dir+1)%4]]==0){
					dir=(dir+1)%4;
				}
			}else{
				if(fie[x+dx[(dir+3)%4]][y+dy[(dir+3)%4]]==0){
					dir=(dir+3)%4;
					x+=dx[dir]*2;
					y+=dy[dir]*2;
					printf("%c",s[dir]);
				}else{
					dir=(dir+2)%4;
					x+=dx[dir]*2;
					y+=dy[dir]*2;
					printf("%c",s[(dir+1)%4]);
					printf("%c",s[dir]);
				}
			}
		}else dir=(dir+1)%4;
		//printf("%d %d %d %d %d\n",x,y,dir,dx[dir],dy[dir]);
		if(x==0 && y==0)break;
	}
	printf("\n");
	return 0;
}