Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

type matrixSize struct{ row, col int }

func calcNum(i, j matrixSize) int {
	return i.row * j.col * i.col
}

func parseProblem() (int, []matrixSize) {
	n := scanInt(sc)
	sizes := make([]matrixSize, n)
	for i := 0; i < n; i++ {
		sizes[i] = matrixSize{row: scanInt(sc), col: scanInt(sc)}
	}
	return n, sizes
}

var dp [][]int

func initDP(n int) {
	dp = make([][]int, n+1)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, n+1)
		for j := 0; j < len(dp[i]); j++ {
			dp[i][j] = math.MaxInt64
		}
	}
}

func resolve(n int, sizes []matrixSize) int {
	// TODO 復習
	initDP(n)
	_rec(sizes, 0, n)
	return dp[0][n]
}

func _rec(sizes []matrixSize, l, r int) int {
	if dp[l][r] != math.MaxInt64 {
		return dp[l][r]
	}
	if r-l <= 1 {
		dp[l][r] = 0
		return 0
	}
	num := math.MaxInt64
	for i := l + 1; i < r; i++ {
		v := _rec(sizes, l, i) + _rec(sizes, i, r) + calcNum(matrixSize{sizes[l].row, sizes[i].row}, matrixSize{sizes[i].row, sizes[r-1].col})
		if v < num {
			num = v
		}
	}
	dp[l][r] = num
	return dp[l][r]
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<iostream>
#include<algorithm>
using namespace std;

static const int N = 100;

int main() {
  int n, p[N + 1], m[N + 1][N + 1];
  cin >> n;
  for ( int i = 1; i <= n; i++ ) {
    cin >> p[i - 1] >> p[i];
  }

  for ( int i = 1; i <= n; i++ ) m[i][i] = 0;
  for ( int l = 2; l <= n; l++ ) {
    for ( int i = 1; i <= n - l + 1; i++ ) {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      for ( int k = i; k <= j - 1; k++) {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i -1] * p[k] * p[j]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;
}

C++: #include<iostream>
#include<climits>
#include<algorithm>
using namespace std;
struct mat{
  int w,h;
};
vector<mat> v;
int memo[101][101];

int solve(int l,int r){
  if(memo[l][r] > 0)return memo[l][r];
  //cout << l << ' ' << r << endl;
  if(l == r)return 0;
  int ret = INT_MAX;
  for(int i = l; i < r; i++){
    int ans = solve(l,i) + solve(i+1,r) + v[l].h * v[i].w * v[r].w;
    ret = min(ret,ans);
  }
  return memo[l][r] = ret;
}
int main(){
  fill(*memo,*(memo+101),-1);
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){
    int r,c;
    cin >> r >> c;
    v.push_back({c,r});
  }
  cout << solve(0,n-1) << endl;
}

C++: #include <iostream> 
#include <cmath> 
#include <climits>
 
using namespace std; 
 
int r[45] = {0}; 
int a[100][100] = {0}; 
 
int f(int n, int m); 
int f(int n, int k, int m); 
 
 
int f(int n, int k, int m) 
{ 
    return f(n,k) * f(k+1,m) + (r[n] * r[k+1] * r[m+1]); 
} 
 
int f(int n, int m) 
{ 
    if (n==m) return 1; 
    int & ra = a[n][m]; 
    if (ra) return ra; 
    ra = INT_MAX; 
    for (int k=n;k<m;k++) 
    { 
        int ans = f(n,k,m); 
        if (ans < ra) ra = ans; 
    } 
    return ra; 
} 
 
int main() 
{ 
    int rr = 0; 
    int cc = 0; 
    int n = 0; 
    cin >> n; 
    for (int i=0;i<n;i++) 
    { 
        cin >> rr >> cc; 
        r[i]=rr; 
        r[i+1]=cc; 
    } 
    for (int i=0;i<n-1;i++) 
    { 
        a[i][i+1] = r[i] * r[i+1] * r[i+2]; 
    } 
    int ans = f(0,n-1); 
    cout << ans << endl; 
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define Lens 105

using namespace std;
int p[Lens];
int C[Lens][Lens];
int N;

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> p[i - 1] >> p[i];
		C[i][i] = 0;
	}
	for (int k = 1; k < N; k++)
	{
		for (int i = 1; i <= N-k; i++)
		{
			int j = i + k;
			C[i][j] = C[i][i] + C[i + 1][j]+p[i-1]*p[i]*p[j];
			for (int t = i+1; t < j; t++)
			{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
				C[i][j] = min(C[i][j], C[i][t] + C[t+1][j] + p[i - 1] * p[t] * p[j]);
			}
		}
	}
	cout << C[1][N];
	return 0;

}

C++: #include<stdio.h>

int main(void) {
  int n, p[101], m[101][101], i, l, j, k, non, temp;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++)
  {
    if (i == 0) scanf("%d %d", &p[0], &p[1]);
    else scanf("%d %d", &non, &p[i + 1]);
  }
  
  for (i = 1; i <= n; i++) m[i][i] = 0;
  
  for (l = 2; l <= n; l++)
  {
    for (i = 1; i <= n - l + 1; i++)
    {
      j = i + l - 1;
      m[i][j] = 10000000000;
      for (k = i; k <= j - 1; k++)
      {
        if (m[i][j] > m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j])
        {
          m[i][j] = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
        }
      }
    }
  }
  
  printf("%d\n", m[i][j]);
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <limits.h>
using namespace std;

int m[101][101]; // m[i][j]: from i to j (columns)
int p[101]; // 
int main(){
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		int r, c; scanf("%d %d", &r, &c);
		p[i] = r; p[i + 1] = c;
	}
	// initialize m[][]
	for (int i = 0; i <= 100; ++i){
		for (int j = 0; j <= 100; ++j) m[i][j] = INT_MAX;
	}
	for (int i = 0; i <= 100; ++i) m[i][i] = 0;
	//
	for (int l = 2; l <= n; ++l){
		for (int i = 1; i <= n-l+1; ++i){
			int j = i + l - 1;
			for (int k = i; k < j; ++k){
				if (m[i][k] == INT_MAX || m[k + 1][j] == INT_MAX) continue;
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << '\n';
}

C++: 
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int p[101];
int M[101][101];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n + 1; i++) {
		cin >> p[i - 1] >> p[i];
	}
	for (int i = 1; i < n + 1; i++)M[i][i] = 0;
	for (int i = 2; i < n + 1; i++) {
		for (int j = 1; j + i - 1 < n + 1; j++) {
			int k = j + i - 1;
			M[j][k] = (1 << 21);
			for (int t = j; t < k; t++) {
				M[j][k] = min(
					M[j][t] + M[t + 1][k] + p[j - 1] * p[t] * p[k],
					M[j][k]
				);
			}
		}
	}
	cout << M[1][n] << endl;
}