Language: C++

#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define INF (1<<30)
#define LINF (1LL<<60)

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1126

#define MAXH 75
#define MAXW 75
vector<vector<string>> dp(MAXH, vector<string>(MAXW));
vector<vector<int>> f(MAXH, vector<int>(MAXW));
string ans;
int W, H;

inline bool str_check(const string& a,const string&b) {
	if (a.size() > b.size()) return true;
	else if (a.size() < b.size()) return false;
	else {
		int Size = a.size();
		for (int i = 0; i < Size;i++) {
			if (a[i] != b[i]) return a[i] > b[i] ? true : false;
		}
	}
	return false;
}

void dfs(int h, int w, vector<vector<char>>& C) {
	f[h][w] = 1;

	bool dfs_f = false;

	if (f[h][w - 1] == 0 && C[h][w - 1] < 'A') {
		if (dp[h][w - 1] == "-") {
			dp[h][w - 1] = C[h][w - 1] + dp[h][w];
			dfs(h, w - 1, C);

			dfs_f = true;
		}
		else {
			if (str_check(C[h][w - 1] + dp[h][w], dp[h][w - 1])) {
				dp[h][w - 1] = C[h][w - 1] + dp[h][w];
				dfs(h, w - 1, C);

				dfs_f = true;
			}
		}
	}

	if (f[h - 1][w] == 0 && C[h - 1][w] < 'A') {
		if (dp[h - 1][w] == "-") {
			dp[h - 1][w] = C[h - 1][w] + dp[h][w];
			dfs(h - 1, w, C);

			dfs_f = true;
		}
		else {
			if (str_check(C[h - 1][w] + dp[h][w], dp[h - 1][w])) {
				dp[h - 1][w] = C[h - 1][w] + dp[h][w];
				dfs(h - 1, w, C);

				dfs_f = true;
			}
		}
	}

	if (!dfs_f) {
		if (str_check(dp[h][w], ans)) {
			ans = dp[h][w];
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (cin >> W >> H) {
		if (W == 0 && H == 0) break;
		ans = "0";
		for (int i = 0; i < MAXH; i++) for (int j = 0; j < MAXW;j++) {
			dp[i][j] = "-";
			f[i][j] = 0;
		}
		vector<vector<char>> C(H + 2, vector<char>(W + 2, 'A'));
		for (int i = 1; i <= H;i++) for (int j = 1; j <= W;j++) cin >> C[i][j];

		for (int i = H; i > 0; i--) {
			for (int j = W; j > 0;j--) {
				if (f[i][j] == 0 && C[i][j] < 'A') {
					dp[i][j] = C[i][j];
					dfs(i, j, C);
				}
			}
		}

		bool zefo_flag = true;
		for (int i = 0; i < ans.length();i++) {
			if (ans[i] == '0' && zefo_flag == true) continue;
			if (ans[i] != '0') zefo_flag = false;
			cout << ans[i];
		}
		cout << endl;
	}
}

void dfs(int h, int w, vector<vector<char>>& C) {
	f[h][w] = 1;

	bool dfs_f = false;

	if (f[h][w - 1] == 0 && C[h][w - 1] < 'A') {
		if (dp[h][w - 1] == "-") {
			dp[h][w - 1] = C[h][w - 1] + dp[h][w];
			dfs(h, w - 1, C);

			dfs_f = true;
		}
		else {
			if (str_check(C[h][w - 1] + dp[h][w], dp[h][w - 1])) {
				dp[h][w - 1] = C[h][w - 1] + dp[h][w];
				dfs(h, w - 1, C);

				dfs_f = true;
			}
		}
	}

	if (f[h - 1][w] == 0 && C[h - 1][w] < 'A') {
		if (dp[h - 1][w] == "-") {
			dp[h - 1][w] = C[h - 1][w] + dp[h][w];
			dfs(h - 1, w, C);

			dfs_f = true;
		}
		else {
			if (str_check(C[h - 1][w] + dp[h][w], dp[h - 1][w])) {
				dp[h - 1][w] = C[h - 1][w] + dp[h][w];
				dfs(h - 1, w, C);

				dfs_f = true;
			}
		}
	}

	if (!dfs_f) {
		if (str_check(dp[h][w], ans)) {
			ans = dp[h][w];
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (cin >> W >> H) {
		if (W == 0 && H == 0) break;
		ans = "0";
		for (int i = 0; i < MAXH; i++) for (int j = 0; j < MAXW;j++) {
			dp[i][j] = "-";
			f[i][j] = 0;
		}
		vector<vector<char>> C(H + 2, vector<char>(W + 2, 'A'));
		for (int i = 1; i <= H;i++) for (int j = 1; j <= W;j++) cin >> C[i][j];

		for (int i = H; i > 0; i--) {
			for (int j = W; j > 0;j--) {
				if (f[i][j] == 0 && C[i][j] < 'A') {
					dp[i][j] = C[i][j];
					dfs(i, j, C);
				}
			}
		}

		bool zefo_flag = true;
		for (int i = 0; i < ans.length();i++) {
			if (ans[i] == '0' && zefo_flag == true) continue;
			if (ans[i] != '0') zefo_flag = false;
			cout << ans[i];
		}
		cout << endl;
	}
}

Compiler output:
a.cc:105:6: error: redefinition of 'void dfs(int, int, std::vector<std::vector<char> >&)'
  105 | void dfs(int h, int w, vector<vector<char>>& C) {
      |      ^~~
a.cc:28:6: note: 'void dfs(int, int, std::vector<std::vector<char> >&)' previously defined here
   28 | void dfs(int h, int w, vector<vector<char>>& C) {
      |      ^~~
a.cc:151:5: error: redefinition of 'int main()'
  151 | int main() {
      |     ^~~~
a.cc:74:5: note: 'int main()' previously defined here
   74 | int main() {
      |     ^~~~