Language: C++

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

int dp[205][205][205][205];
int H, W;
int a[205][205];

int main(){
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> a[i][j];
		}
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			for(int k = 0; k < H; k++){
				for(int l = 0; l < W; l++){
					dp[i][j][k][l] = - INT_MAX;
				}
			}
		}
	}


	dp[0][0][0][0] = 0;

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			for(int k = 0; k < H; k++){
				for(int l = 0; l < W; l++){
					if(i == k && j == l){
						if(i != H - 1){
							if(k != H - 1){
								dp[i+1][j][k+1][l] = max(dp[i+1][j][k+1][l], dp[i][j][k][l] + a[i][j]);
							}
							if(l != W - 1){
								dp[i+1][j][k][l+1] = max(dp[i+1][j][k][l+1], dp[i][j][k][l] + a[i][j]);
							}
						}
						if(j != W - 1){
							if(k != H - 1){
								dp[i][j+1][k+1][l] = max(dp[i][j+1][k+1][l], dp[i][j][k][l] + a[i][j]);
							}
							if(l != W - 1){
								dp[i][j+1][k][l+1] = max(dp[i][j+1][k][l+1], dp[i][j][k][l] + a[i][j]);
							}
						}

					}else{
						if(i != H - 1){
							if(k != H - 1){
								dp[i+1][j][k+1][l] = max(dp[i+1][j][k+1][l], dp[i][j][k][l] + a[i][j] + a[k][l]);
							}
							if(l != W - 1){
								dp[i+1][j][k][l+1] = max(dp[i+1][j][k][l+1], dp[i][j][k][l] + a[i][j] + a[k][l]);
							}
						}
						if(j != W - 1){
							if(k != H - 1){
								dp[i][j+1][k+1][l] = max(dp[i][j+1][k+1][l], dp[i][j][k][l] + a[i][j] + a[k][l]);
							}
							if(l != W - 1){
								dp[i][j+1][k][l+1] = max(dp[i][j+1][k][l+1], dp[i][j][k][l] + a[i][j] + a[k][l]);
							}
						}
					}
				}
			}
		}
	}


	cout << dp[H-1][W-1][H-1][W-1] + a[H-1][W-1] << endl;





}


Compiler output:
/tmp/ccBLflmI.o: in function `main':
a.cc:(.text+0xb): relocation truncated to fit: R_X86_64_PC32 against symbol `H' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `W' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x7e): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x9d): relocation truncated to fit: R_X86_64_PC32 against symbol `W' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0xac): relocation truncated to fit: R_X86_64_PC32 against symbol `H' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x145): relocation truncated to fit: R_X86_64_PC32 against symbol `W' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x154): relocation truncated to fit: R_X86_64_PC32 against symbol `H' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x167): relocation truncated to fit: R_X86_64_PC32 against symbol `W' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x17a): relocation truncated to fit: R_X86_64_PC32 against symbol `H' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x1db): relocation truncated to fit: R_X86_64_PC32 against symbol `H' defined in .bss section in /tmp/ccBLflmI.o
a.cc:(.text+0x1ed): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status