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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int MAX_L = 10000;
int N;

struct Matrix{ int R, W; };
Matrix M[MAX_N];

int mem[MAX_L][MAX_L];
Matrix memM[MAX_L][MAX_L];


void eval(Matrix M[], int s, int e){

	if (s == e){
		mem[s][e] = 0;
		memM[s][e] = M[s];
		return;
	}

	int minval = 1000000000;
	for (int mid = s; mid < e; mid++){
		Matrix m1 = memM[s][mid];
		Matrix m2 = memM[mid+1][e];
		int val = mem[s][mid] + mem[mid+1][e] + (m1.W * m1.R * m2.W);
		
		if (val < minval){
			minval = val;
			mem[s][e] = val;
			Matrix m; m.R = m1.R; m.W = m2.W;
			memM[s][e] = m;
		}
	}

}

int solve(Matrix M[], int N){

	for (int d = 0; d <= N; d++)
		for (int s = 0; s + d <= N; s++)
		{
			eval(M, s, s + d);
		}

	return mem[0][N];
}

int main() {

	cin >> N;
	rep(i, N){
		Matrix m;
		cin >> m.R;
		cin >> m.W;
		M[i] = m;
	}

	cout << solve(M, N) << endl;

	// debug
	rep (i, N){
		rep(j, N){
			cerr << mem[i][j] << ' ';
		}
		cerr << endl;
	}
}

C++: #include<iostream>
#include<stdio.h>
#include<algorithm>

using namespace std;

void output(int, int, int, int);

#define MAX 100
#define INF (1 << 21)

int SIZE;
int R[MAX + 2];
int C[MAX + 1][MAX + 1];
int B[MAX + 1][MAX + 1];

void compute() {
	for (int i = 1; i <= SIZE; i++)
		for (int j = 1; j <= SIZE; j++) C[i][j] = INF;

	for (int i = 1; i <= SIZE; i++) C[i][i] = 0;

	for (int j = 1; j <= SIZE - 1; j++) {
		for (int i = 1; i <= SIZE - j; i++) {
			for (int k = i + 1; k <= i + j; k++) {
				int cost = C[i][k - 1] + C[k][i + j] + R[i] * R[k] * R[i + j + 1];
				if (cost < C[i][i + j]) {
					C[i][i + j] = cost;
					B[i][i + j] = k;
				}

			}
		}
	}
}


void input() {
	int r, c;
	cin >> SIZE;
	for (int i = 1; i <= SIZE; i++) {
		cin >> r;
		cin >> c;
		R[i] =r;
	}
	R[SIZE + 1] = c;

}

void output() {
	cout << C[1][SIZE] << endl;
}

int main() {
	input();
	compute();
	output();
}

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;
}