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 <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[111][111],n,L[111],R[111];

int dfs(int l,int r){
	if(dp[l][r]!=-1)return dp[l][r];
	int res=1e9;
	for(int i=l;i<r;i++){
		res=min(res,dfs(l,i)+dfs(i+1,r)+L[l]*R[i]*R[r]);
	}
	return dp[l][r]=res;
}

signed main(){
	memset(dp,-1,sizeof(dp));
	r(i,111)dp[i][i]=0;
	cin>>n;
	r(i,n)cin>>L[i]>>R[i];
	cout<<dfs(0,n-1)<<endl;
}

C++: /*
** Matrix Chain Multiplication
*/

# include <cstdio>
# include <algorithm>
using namespace std;

const int MAX = 100 + 5;

int n, m[MAX][MAX], p[MAX];

void matrixCM() {
    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; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
}

void solve() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &p[i], &p[i + 1]);
    }
    matrixCM();
    printf("%d\n", m[1][n]);
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}

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

int main()
{
	int n, p = 0, m = 101, mini;
	int v[101];

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v[i] >> v[i + 1];
		if (m > v[i]) {
			m = v[i];
			mini = i;
		}
	}

	if (n > 1) {
		for (int j = 0; j < n; j++)
			p += v[j] * v[j + 1];

		if (mini == 0) {
			p -= v[0] * v[1];
			p *= v[0];
		}
		else if (mini == n) {
			p -= v[n - 1] * v[n];
			p *= v[n];
		}
		else {
			p -= v[mini] * (v[mini + 1] + v[mini - 1]);
			p *= v[mini];
			p += v[0] * v[mini] * v[n];
		}
	}

	cout << p << 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=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<algorithm>
using namespace std;

#define MAX_N 10000
#define INF 10000000LL

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

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[i][k] + x[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	sum = x[1][n];
	return sum;
}

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

C++: 
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

ll INF = 1LL << 31;
int main()
{
    int n;
    cin >> n;
    vector<P> m(n);
    rep(i, n) cin >> m[i].first >> m[i].second;

    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INF));
    rep(i, n + 1) dp[i][i] = 0;

    // start by doing a 1 matrix times 1 matrix multiplication
    // AB = A.x * A.y * B.y
    for (int w = 1; w <= n; w++)
    {
        // for each possible left most matrix for each width
        // i.e. until your "right" matrix defined by the width is m[n-1]
        for (int l = 0; l <= n - w; l++)
        {
            // as seen here.
            int r = l + w - 1;

            // for every matrix inbetween:
            for (int k = l; k < r; k++)
            {
                // multiplying (AB)(CDE) gives you an (A.x * B.y) x (C.x=B.y * E.y) mult.
                // Thus, this is a A.x * B.y * E.y + dp[A][B] + dp[C][E].

                // Do this for all possible combinations
                // e.g. A(BCD), (AB)(CD), (ABC)D where ABC-> A(BC) or (AB)C , etc.
                chmin(dp[l][r], m[l].first * m[k].second * m[r].second + dp[l][k] + dp[k + 1][r]);
            }
        }
    }

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

    return 0;
}

C++: /*
 * Problem Description: Matrix Chain Multiplication
 * Category: Dynamic Programming
 * Author: Khan
 * Date: 20th October, 2017
 */

#include <iostream>
#include <algorithm>

using namespace std;

#define N 100

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    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>
#define N 105
using namespace std;
int n,u,k,v,e[N][N],cnt;
int ans1[N],ans2[N];
bool used[N];
 
void dfs(int x){
  if(used[x])return;
  used[x]=true;
  ans1[x]=cnt++;
  for(int i=0;i<n;i++)
    if(e[x][i])dfs(i);
  ans2[x]=cnt++;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++)
      cin>>v,e[u-1][v-1]=1;
  }
  cnt=1;
  for(int i=0;i<n;i++){
    if(!used[i])dfs(i);
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<' '<<ans1[i]<<' '<<ans2[i]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define INF (int) 2e9
#define MOD (int) 1e9 + 7

#define MAX_N 100

int memo[MAX_N][MAX_N];
int row[MAX_N], col[MAX_N];

int f(int l, int r, int pos){
    if(pos != -1){
        if(pos == r){
            return INF;
        }
        return min(f(l, pos, -1) + f(pos + 1, r, -1) + row[l] * col[pos] * col[r], f(l, r, pos + 1));
    }
    if(memo[l][r]>0) return memo[l][r];
    if(r-l==0){
        return 0;
    }
    return memo[l][r] = f(l, r, l);
}

int main(){
    int n;
    cin >> n;
    
    rep(i, n){
        cin >> row[i] >> col[i];
    }
    cout << f(0, n-1, -1) << endl;
    return 0;
}