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<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<20;i++){
		for(int j=0;j<20;j++){
			if(-1<i&&i<maphor[0].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){
		for(int i=0;i<5;i++){
			if(i==4)return -1;
			if(count!=0
				&&x==0
				&& y==0
				&&(((v+loop[i])%4)==2 || ((v+loop[i])%4==1))){
				return 0;
			}
			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;
			}
			count++;
		}
	}
}

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 <string>
#include <array>
#include <bitset>
#include <cstdint>

int main()
{
	enum { Left, Up, Right, Down };

	typedef std::array<std::bitset<4>, 5> Row;
	typedef std::array<Row, 5> Matrix;
	Matrix matrix;
	for (auto& row : matrix) {
		row.fill(std::bitset<4>());
	}

	std::string input;
	std::getline(std::cin, input);
	for (std::uint16_t x = 0; x < 4U; ++x) {
		if (input[x] == '1') {
			matrix[0][x].set(Right);
			matrix[0][x + 1].set(Left);
		}
	}

	for (std::uint16_t y = 0; y < 4U; ++y) {
		std::getline(std::cin, input);
		for (std::uint16_t x = 0; x < 5U; ++x) {
			if (input[x] == '1') {
				matrix[y][x].set(Down);
				matrix[y + 1][x].set(Up);
			}
		}
		std::getline(std::cin, input);
		for (std::uint16_t x = 0; x < 4U; ++x) {
			if (input[x] == '1') {
				matrix[y + 1][x].set(Right);
				matrix[y + 1][x + 1].set(Left);
			}
		}
	}

	std::uint16_t y = 0, x = 0;
	char direct = 'R';
	do {
		if (direct == 'R') {
			if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
			else if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
			else if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
		}
		else if (direct == 'D') {
			if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
			else if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
			else if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
		}
		else if (direct == 'L') {
			if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
			else if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
			else if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
		}
		else if (direct == 'U') {
			if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
			else if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
			else if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
		}
		std::cout << direct << std::flush;
	} while (not (y == 0 and x == 0));
	std::cout << std::endl;

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
#include <cassert>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

char m[10][10];

bool end(int x, int y) {
  return (x == 1 && y == 1) || (x == 0 && y == 1) ;
}

void check(int x, int y, int d) {
  printf("x,y = %d,%d : %d\n", x, y, d);
  assert(false);
}

int main() {
  memset(m, 0, sizeof m);
  string ans = "R";
  rep(i,9) scanf(" %s", m[i]);
  rep(i,9) {
    rep(j,5) {
      m[i][j] = (m[i][j] == '1') ? 1 : 0 ;
    }
  }
  // rep(i,9) {
  //   rep(j,5) printf("%2d", m[i][j]); puts("");
  // }

  int x = 1, y = 0, d = 1;
  do {
    // printf("(%d,%d) : %d : %s\n", x, y, d, ans.c_str());
    switch (d) {
      case 0: {
        // up
        if (m[2*(y-2)+1][x]) {
          // ok
          ans += 'U';
          --y;
        } else if (m[2*(y-1)][x]) {
          // ok
          ans += 'R';
          d = 1;
          ++x; --y;
        } else if (m[2*(y-1)][x-1]) {
          ans += 'L';
          d = 3;
        } else {check(x,y,d);}
        break;
      }
      case 1: {
        // right
        if (m[2*y][x]) {
          // ok
          ans += 'R';
          ++x;
        } else if (m[2*(y-1)+1][x]) {
          ans += 'U';
          d = 0;  
        } else if (m[2*y+1][x]) {
          // ok
          ans += 'D';
          d = 2;
          ++x; ++y;
        } else {check(x,y,d);}
        break;        
      }
      case 2: {
        // down
        if (m[2*y+1][x-1]) {
          // ok
          ans += 'D';
          ++y;
        } else if (m[2*y][x-1]) {
          ans += 'R';
          d = 1;
        } else if (m[2*y][x-2]) {
          // ok
          ans += 'L';
          d = 3;
          --x; ++y;
        } else {check(x,y,d);}
        break;
      }
      case 3: {
        // left
        if (m[2*(y-1)][x-2]) {
          // ok
          ans += 'L';
          --x;
        } else if (m[2*(y-2)+1][x-1]) {
          // ok
          ans += 'U';
          d = 0;
          --x; --y;
        } else if (m[2*(y-1)+1][x-1]) {
          ans += 'D';
          d = 2;
        } else {check(x,y,d);}
        break;        
      }
    }
  } while (!end(x,y));
  if (x == 1 && y == 1 && d == 0) ans += 'L';
  printf("%s\n", ans.c_str());
  return 0;
}