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 <cstdio>
#include <climits>

int convert(int p, int size, int n){
    for(int i=1;i<size;i++)p+=n--;
    return p;
}

int multipulication(int *r, int *c, int *count, int p, int size, int n){
    if(size==1)return 0;
    int id = convert(p,size,n);
    if(count[id])return count[id];
    int mlt = INT_MAX;
    int i, tmp;
    for(i=1;i<size;i++){
        tmp = r[p]*r[p+i]*c[p+size-1] + multipulication(r,c,count,p,i,n) + multipulication(r,c,count,p+i,size-i,n);
        if(tmp<mlt)mlt=tmp;
    }
    count[id] = mlt;
    return mlt;
}

int main(){
    int i, n;
    scanf("%d",&n);
    int r[n];
    int c[n];
    int count[n*(n+1)/2];
    for(i=0;i<n*(n+1)/2;i++)count[i]=0;
    for(i=0;i<n;i++)scanf("%d %d",r+i,c+i);
    printf("%d\n",multipulication(r,c,count,0,n,n));
    return 0;
}

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

#define MAX_N 10000
#define INF 10000000LL

long long n, j, x[MAX_N][MAX_N], p[MAX_N + 2];

int matrix() {
	for (int i = 0; i < n; i++) { x[i][i] = 0; }
	for (int h = 2; h <= n; h++) {
		for (int i = 1; i <= n - h + 1; i++) {
			j = i + h - 1;
			x[i][j] = INF;
			for (int k = i; k < j; k++) {
				x[i][j] = min(x[i][j], x[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	return x[1][n];
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}
	cout << matrix() << endl;
	return 0;
}

C++: /**
 * 	matrix chain multiplication
 * 	f(n,m) = multiply Mn*M(n+1)*...*M(m-1)*M(m)
 * 	f(n,n) = 1
 * 	r(n)=c(n-1)
 * 	f(n,n+1) = C(n) * R(n) * C(n+1) = c(n) * c(n-1) * c(n+1)
 * 	f(n,k,m) = f(n,k)*f(k+1,m)*C(n)*r(n)*c(k)
 * 	f(n,m) = min(f(n,k,m)
 */

#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 0;
	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 <stdlib.h>
#include <stdio.h>

int MCM(int n){
int i,j,k,l,m[101][101],p[101],x;

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]=10000000;
        for(k=i;k<=j;k++){
            x=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
            if(m[i][j]>x)m[i][j]=x;
            }
        }
    }
return m[i-1][j];
}

int main(){

int i,n,m[101];

scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d %d",&m[i],&m[i+1]);
   }
printf("%d\n",MCM(n));
return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[101][101];
	int p[101];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p[i-1]>>p[i];
	}
	for(int i=1;i<=n;i++)a[i][i]=0;
	for(int l=2;l<=n;l++){
		for(int i=1;i<=n-l+1;i++){
			int j=i+l-1;
			a[i][j]=(1<<21);
			for(int k=i;k<=j-1;k++){
				a[i][j]=min(a[i][j],a[i][k]+a[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	cout<<a[1][n]<<endl;
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

int R[101], C[101];
int dp[101][101];

int f(int l, int r) {
	dump(l, r);
	if (dp[l][r] != INF)return dp[l][r];
	if (l >= r - 1)return 0;
	rep(m, l + 1, r) {
		chmin(dp[l][r], f(l, m) + f(m, r) + R[l] * R[m] * C[r - 1]);
	}
	return dp[l][r];
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	rep(i, 0, n)cin >> R[i] >> C[i];
	memset(dp, 0x3f, sizeof(dp));
	cout << f(0, n) << endl;
	return 0;
}

C++: #include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n;cin>>n;
  vll p(n+1);
  vvll dp(n,vll(n,MOD));
  rep(i,0,n){
    cin>>p[i]>>p[i+1];
  }
  rep(i,0,n){
    dp[i][i]=0;
  }
  rep(haba,0,n){
    rep(i,0,n-haba){
      int j=i+haba;
      rep(k,i,j){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i]*p[k+1]*p[j+1]);
      }
    }
  }
  cout<<dp[0][n-1]<<endl;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };

int main(void) {
    int n;

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

C++: #include<bits/stdc++.h>
using namespace std;

long long int n, mat[100+1][100+1], len[100+1];

int main(void){
  int i, j, k, l;

  scanf("%d", &n);
  
  for(int i=1; i<=n; i++){
    scanf("%d %d", &len[i-1], &len[i]);
  }
  
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      mat[i][j]=INT_MAX;

      for(k=i; k<=j-1; k++){
	mat[i][j]=min(mat[i][j], mat[i][k]+mat[k+1][j]+len[i-1]*len[k]*len[j]);
      }
    }
  }

  printf("%d\n", mat[1][n]);
  
  return 0;
}