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 <algorithm>
#include <vector>
#include <climits>
#define range(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;

int n;
int m[110][110];
int p[110];

int matrixChainMultiplication() {
  rep1(i, n) m[i][i] = 0;

  range(l, 2, n) {
    rep1(i, n - 1 + 1) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      range(k, i, j - 1) {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }
  return m[1][n];
}

int main() {
  cin >> n;
  rep1(i, n) {
    cin >> p[i - 1] >> p[i];
  }
  cout << matrixChainMultiplication() << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 29);

struct Matrix
{
  int r, c;
};

vector<Matrix> M;

int rec(vector<vector<int>> &dp, int top, int bottom)
{
  if (dp.at(top).at(bottom) != INF)
  {
    return dp.at(top).at(bottom);
  }
  if (top == bottom)
  {
    dp.at(top).at(bottom) = 0;
    return 0;
  }
  for (int mid = top; mid < bottom; mid++)
  {
    dp.at(top).at(bottom) = min(dp.at(top).at(bottom), rec(dp, top, mid) + rec(dp, mid + 1, bottom) + M.at(top).r * M.at(mid).c * M.at(bottom).c);
  }
  return dp.at(top).at(bottom);
}

int main()
{
  int n;
  cin >> n;
  M.resize(n);
  for (int i = 0; i < n; i++)
  {
    int r, c;
    cin >> r >> c;
    M.at(i) = Matrix{r, c};
  }
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, INF));
  cout << rec(dp, 0, n - 1) << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int, int>;

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<bits/stdc++.h>
using namespace std;
#define N 100
#define INF 1<<25
int n,p[N+1],m[N+1][N+1];
int matrixchainmultiplication(){
  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]=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]);
      }
    }
  }
  return m[1][n];
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>p[i]>>p[i+1];
  cout<<matrixchainmultiplication()<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define roop(i, a, n) for(ll i = (a); i < (n); i++)
using namespace std;
using ll = long long;

int main(){
    ll n; cin >> n;
    ll dp[n+1][n+1];
    ll a[n+1];
    roop(i, 1, n+1) cin >> a[i - 1] >> a[i];

    roop(i, 1, n+1) dp[i][i] = 0;
    roop(l, 2, n+1){
        roop(i, 1, n-l+2){
            ll j = i + l - 1;
            dp[i][j] = INT_MAX;
            roop(k, i, j) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + a[i-1]*a[k]*a[j]);
        }
    }
    cout << dp[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 n = 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 (i = 1; i <= n; 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<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int num;
  cin>>num;
  vector<int> m(num+1);
  for(int i=0;i<num;i++) cin>>m.at(i)>>m.at(i+1);

  //dp[i][j]はi行列iからjまでの計算回数の最小値を格納している
  int dp[num+1][num+1];
  //スタートとゴールは等しくならないので0を入れる
  for(int i=1;i<=num;i++) dp[i][i]=0;


  //対象とする行列の数l
  for(int l=2;l<=num;l++)
  {
    for(int i=1;i<=num-l+1;i++)
    {
      int j=i+l-1;
      dp[i][j]=(1<<21);
      for(int k=i;k<=j-1;k++)
      {
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+m.at(i-1)*m.at(k)*m.at(j));
      }
    }
  }
  cout<<dp[1][num]<<endl;


}

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];  //  M[i]がp[i-1]*p[i]の行列となるような1次元配列
    }

    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 <iostream>
using namespace std;

#define N 100
#define MAX 100000

int main(void) {
    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; //対角成分は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] = MAX;
            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;
}

C++: #line 1 "../lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "tmp.cpp"

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

  int n;
  cin >> n;
  vi a;
  REP(i, n) {
    int r, c;
    cin >> r >> c;
    if (i == 0)
      a.push_back(r);
    a.push_back(c);
  }

  vector<vi> dp(n + 1, vi(n + 1, 1e9));
  REP(k, n + 1) {
    REP(i, n + 1 - k) {
      if (k < 2) {
        dp[i][i + k] = 0;
      } else {
        REP(j, k) { dp[i][i + k] = min(dp[i][i + k], dp[i][i + j] + dp[i + j][i + k] + a[i] * a[i + j] * a[i + k]); }
      }
    }
  }

  cout << dp[0][n] << endl;

  return 0;
}