Go: package main

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

var cache [100][100]int

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	tables := []table{}
	for i := 0; i < num; i++ {
		sc.Scan()
		num1, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		num2, _ := strconv.Atoi(sc.Text())
		t := table{num1, num2}
		tables = append(tables, t)
	}

	fmt.Println(minimum(0, len(tables)-1, tables))
}

type table struct {
	v int
	h int
}

func minimum(i int, j int, t []table) int {
	if i == j {
		return 0
	}

	// fmt.Printf("i:%v j:%v\n", i, j)
	if cache[i][j] != 0 {
		return cache[i][j]
	}

	min := math.MaxInt64
	for k := i; k < j; k++ {
		p := t[i].v
		n := t[k].h
		q := t[j].h
		val := minimum(i, k, t) + minimum(k+1, j, t) + p*n*q
		if val < min {
			min = val
		}
	}

	cache[i][j] = min
	return min
}

C++: #include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;

vector<int> r(100), c(100);
vector<vector<int>> dp(100, vector<int>(100, -1));
int rec(int left, int right){
  if (right - left == 0) return 0;
  if (right - left == 1) return r[left] * r[right] * c[right];
  if (dp[left][right] != -1) return dp[left][right];
  int min;
  rep2(mid, left, right){
    min = rec(left, mid) + rec(mid+1, right) + r[left] * c[mid] * c[right];
    if (dp[left][right] == -1 || dp[left][right] > min) dp[left][right] = min;
  }
  return dp[left][right];
}

int main(){
  int n;
  cin >> n;
  rep(i, n) cin >> r[i] >> c[i];
  int ans = rec(0, n-1);
  cout << ans << endl;
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
static const int INFTY = (1 << 21);

int main() {
    int n;
    cin >> n;
    int p[n + 1], m[n + 1][n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> p[i - 1] >> p[n];
        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] = INFTY;
            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 <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	int INFTY = 1000000000;

	int n;
	scanf("%d", &n);

	int p[n + 1];
	for (int i = 0; i < n; i++) {
		scanf("%d %d", p + i, p + i + 1);
	}

	int m[n + 1][n + 1];

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			m[i][j] = 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] = INFTY;
			for (int k = i; k < j; ++k) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
				cout << i << ":" << j << "," << m[i][j] << endl;
			}
		}
	}
	cout << m[1][n] << endl;

	return 0;
}

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 = 0;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 <vector>
#define eol '\n'
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector< vector<int> > mat(n, vector<int>(n, (1 << 21)));
  vector<int> r(n), c(n);
  
  for (int i = 0; i < n; i++) {
    mat[i][i] = 0;
    cin >> r[i] >> c[i];
  }
  
  for (int l = 1; l < n; l++) {
    for (int i = 0; i < n - l; i++) {
      int j = i + l;
      for (int k = i; k < j; k++) {
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k+1][j] + r[i] * c[k] * c[j]);
      }
    }
  }

  cout << mat[0][n-1] << eol;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define MAX 100
int main() {

    int n;
    cin >> n;
    int p[MAX+1], m[MAX+1][MAX+1];
    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] = INT_MAX;     //INFいれる
            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 <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int n;
int m[110][2], dp[110][110];

int rec(int l, int r) {
    if (dp[l][r] != -1) {
        return dp[l][r];
    }

    if (abs(l - r) <= 1) {
        return dp[l][r] = 0;
    }

    int res = iINF;

    if (abs(l - r) == 2) {
        return dp[l][r] = m[l][0] * m[l][1] * m[r - 1][1];
    }

    for (int mid = l + 1; mid < r; mid++) {
        res = min(
            res, rec(l, mid) + rec(mid, r) + m[l][0] * m[mid - 1][1] * m[r - 1][1]);
    }

    return dp[l][r] = res;
}

int main() {
    cin >> n;
    REP(i, n) {
        int r, c;
        cin >> r >> c;
        m[i][0] = r;
        m[i][1] = c;
    }

    memset(dp, -1, sizeof(dp));

    cout << rec(0, n) << endl;
    return 0;
}

C++: #include <iostream> 
#include <math.h> 
 
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; 
}