Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

type matrixSize struct{ row, col int }

func calcNum(i, j matrixSize) int {
	return i.row * j.col * i.col
}

func parseProblem() (int, []matrixSize) {
	n := scanInt(sc)
	sizes := make([]matrixSize, n)
	for i := 0; i < n; i++ {
		sizes[i] = matrixSize{row: scanInt(sc), col: scanInt(sc)}
	}
	return n, sizes
}

var dp [][]int

func initDP(n int) {
	dp = make([][]int, n+1)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, n+1)
		for j := 0; j < len(dp[i]); j++ {
			dp[i][j] = math.MaxInt64
		}
	}
}

func resolve(n int, sizes []matrixSize) int {
	// TODO 復習
	initDP(n)
	_rec(sizes, 0, n)
	return dp[0][n]
}

func _rec(sizes []matrixSize, l, r int) int {
	if dp[l][r] != math.MaxInt64 {
		return dp[l][r]
	}
	if r-l <= 1 {
		dp[l][r] = 0
		return 0
	}
	num := math.MaxInt64
	for i := l + 1; i < r; i++ {
		v := _rec(sizes, l, i) + _rec(sizes, i, r) + calcNum(matrixSize{sizes[l].row, sizes[i].row}, matrixSize{sizes[i].row, sizes[r-1].col})
		if v < num {
			num = v
		}
	}
	dp[l][r] = num
	return dp[l][r]
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<22;

// dp[i][j] := [i , j]??????????????????????????則???????????????????属???即????????属
// |(4*5   (5*3)  3*2)|  2*1
int main()
{
	int n, dp[128][128], r[128];
	P T[128];

	cin >> n;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
		 	dp[i][j] = INF;
		}
	}
	/*
	for(int i = 0; i < n; i++)
	{
		dp[i][i] = 0;
	}
	*/
	for(int i = 0; i < n; i++)
	{
		cin >> T[i].first >> T[i].second;
		dp[0][i] = 0;
	}
	/*
	r[0] = T[0].first;
	for(int i = 0; i < n; i++)
	{
		r[i+1] = T[i].second;
	}
	*/
	/*
	for(int i = 0; i <= n; i++)
	{
		cout << r[i] << endl
	}
	*/
	/*
	for(int l = 1; l < n; l++)
	{
		for(int i = 0; i < n-l; i++)
		{ 
			int j = i + l;
			for(int k = 1; k <= l; k++)
			{
				dp[i][j] = std::min(dp[i][j], dp[i][i + k - 1] + dp[i + k][j] + T[i].first*T[i + k].first*T[j].second); //r[j]*r[k]*r[i+j+1]);
			}
		}
	}
*/
	for(int i = 1; i < n; i++)
	{
		for(int j = 0; j < n-i; j++)
		{ 
			for(int k = 1; k <= i; k++)
			{
				dp[i][j] = std::min(dp[i][j], dp[k-1][j] + dp[i-k][j+k] + T[j].first*T[j + k].first*T[j + i].second); //r[j]*r[k]*r[i+j+1]);
				//printf("%3d : %3d : %3d => %3d\n", i, j, k, dp[i][j]);
				//puts("run");
			}
		}
	}

	/*
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			printf("%10d ",dp[i][j]);
		}
		puts("");
	}
    */	

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

C++: #include<iostream>
#include<algorithm>

using namespace std;

int main {

    int i, j, k, l, n, p[101], m[101][101];

    cin >> n;

    for (i = 1; i <= n; i++) {
        cin >> p[i - 1] >> p[i];
    }

    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] = (1 << 21);

            for (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 <cstdlib>
#include <climits>

/*
 * http://ttrsq.exblog.jp/24318687/
 */

const int MAX_N = 100;
int DP[MAX_N + 1][MAX_N + 1] = {0};
int *p;

int best(int r, int c) {
  int min = INT_MAX;
  int num = c - r;

  for (int i = 0; i < num; i++) {
    min = std::min(min, DP[r][r + i] + DP[r + i + 1][c] + p[r - 1] * p[r + i] * p[c]);
  }
  
  return min;
}

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

  int n = 0;
  std::cin >> n;

  if (n == 1) {
    std::cout << "0" << std::endl;
  }
  
  p = (int *) std::malloc(sizeof(int) * n + 1);

  int bb = 0;

  std::cin >> p[0];
  std::cin >> p[1];
  
  for (int i = 2; i <= n; i++) {
    std::cin >> bb;
    std::cin >> p[i];
  }

  for (int i = 1; i < n; i++) {
    DP[i][i + 1] = p[i - 1] * p[i] * p[i + 1];
  }

  for (int j = 0; j <= n - 3; j++) {
    for (int i = j + 3; i <= n; i++) {
      DP[i - 2 - j][i] = best(i - 2 - j, i);
    }
  }

  std::cout << DP[1][n] << std::endl;

  return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> p[i] >> p[i + 1];
  }
  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      if (i == j)
        dp[i][j] = 0;
      else {
        int tmp = 1e9;
        for (int k = i; k < j; k++) {
          tmp = min(tmp, dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
        }
        dp[i][j] = tmp;
      }
    }
  }
  debug(dp);
  cout << dp[1][n] << endl;
  return 0;
}

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

const int INF = 1 << 28;

int main()
{
    int n;
    int dp[101][101];
    int r[102];
    
    cin >> n;
    
    fill((int*)dp, (int*)(dp + n), INF);
    
    for(int i = 0; i < n; ++i){
        cin >> r[i] >> r[i + 1];
        dp[i][i] = 0;
    }
    
    for(int w = 1; w < n; ++w){
        for(int i = 0, j ; j = i + w, j < n; ++i){
            for(int k = i; k < j; ++k){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + r[i] * r[k + 1] * r[j + 1]);
            }
        }
    }
    
    cout << dp[0][n-1] << endl;
    
}