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++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

uint64_t solve(const vector<pair<int, int>>& mat) {
  if (mat.size() < 2) {
    return 0ULL;
  }
  auto n = mat.size();
  vector<vector<uint64_t>> cache(n - 1, vector<uint64_t>(n, no_value));
  for (size_t range = 2; range <= n; ++range) {
    for (size_t first = 0; ; ++first) {
      auto last = first + range - 1;
      if (last == n) {
        break;
      }
      for (size_t mid = first; mid != last; ++mid) {
        auto lhs = first == mid ? 0 : cache[first][mid];
        auto rhs = (mid + 1) == last ? 0 : cache[mid + 1][last];
        auto mul = mat[first].first * mat[last].second * mat[mid].second;
        cache[first][last] = min(cache[first][last], lhs + rhs + mul);
      }
    }
  }
  return cache[0][n - 1];
}

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> mat;
  for (int i = 0; i < n; ++i) {
    int row, col;
    cin >> row >> col;
    mat.push_back(make_pair(row, col));
  }
  uint64_t result = solve(mat);
  cout << result << endl;
}

C++: #pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int r[105],c[105],dp[105][105]={0};
int main(){
	int i,j,k,n,len;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d",&r[i],&c[i]);
	for(i=0;i<n-1;i++)
		dp[i][i+1]=r[i]*c[i]*c[i+1];
	for(len=3;len<=n;len++){
		for(i=0;i<n-len+1;i++){
			j=i+len-1;
			dp[i][j]=2147483647;
			for(k=i;k<j;k++){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
			}
		}
	}
	printf("%d\n",dp[0][n-1]);
}

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

int solve(int n, vector<int> & dims){
    int dp[100][101] = {{0}};
    for (int span = 2; span != n + 1; ++span){
        for (int first = 0; first + span != n + 1; ++first){
            for (int last = first + span; last != n + 1; ++last){
                int record = 2000000000;
                for (int mid = first + 1; mid != last; ++mid){
                    record = min(record, dp[first][mid] + dp[mid][last] + dims[first] * dims[last] * dims[mid]);
                }
                dp[first][last] = record;
            }
        }
    }
    return dp[0][n];
}


int main()
{
    int n = 0;
    cin >> n;
    vector<int> dims(n + 1);
    int r = 0;
    int c = 0;
    for (int i = 0; i != n; ++i){
        cin >> r >> c;
        dims[i] = r;
    }
    dims[n] = c;
    cout << solve(n, dims) << endl;
    return 0;
}

C++: /*
 * aoj/alds1_10_b_2nd/main.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const ll INF = 100000000000000000;
// 1 1
// 1 1
// 1 1
//
// 1 1 1
// 1 1 1
//
struct Mat {
  ll r, c, count;
  Mat operator * (Mat v) {
    assert(c == v.r);
    ll numOp = r * v.c * c;
    return (Mat){ r, v.c, numOp + count + v.count };
  }
  bool operator == (const Mat &v) const {
    return r == v.r && c == v.c;
  }
  bool operator < (const Mat &v) const {
    assert(v.count == INF or (r == v.r and c == v.c));
    return count < v.count;
  }
  bool operator > (const Mat &v) const {
    // cout << r << " " << v.r << " " << c << " " << v.c << " " << count << " " << v.count << endl;
    assert(v.count == INF or count == INF or (r == v.r and c == v.c));
    return count > v.count;
  }
};

const int MAX = 110;
ll N;
vector<Mat> A;

// dp[l][r] := [l:r)の範囲の行列を掛け算する時の最小回数.
Mat dp[MAX][MAX];

void input() {
  cin >> N;
  ll r, c;
  loop(n,0,N) {
    cin >> r >> c;
    A.push_back({ r, c, 0 });
  }
}

ll receive() {
  for (int len=0; len<=N; len++) {
    for (int l=0; l+len<=N; l++) {
      int r = l+len;
      dp[l][r] = Mat({ 0, 0, INF });
    }
  }

  for (int l=0; l<N; l++) dp[l][l+1] = A[l];
  for (int len=2; len<=N; len++) {
    for (int l=0; l+len<=N; l++) {
      int r = l+len;
      for (int k=l+1; k<r; k++) {
        chmin(dp[l][r], dp[l][k] * dp[k][r]);
      }
    }
  }

  return dp[0][N].count;
}

void solve() {
  cout << receive() << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e14;

signed
main(){
		int n;
		cin >> n;
		vector<ll> p(n+1);
		for(int i=0;i<n;i++)
		{
				cin >> p[i] >> p[i+1];
		}
		vector<vector<ll> > m(n+1,vector<ll>(n+1, INF));

		for(int i=1;i<=n;i++)	m[i][i] = 0;

		for(int sa=1;sa<n;sa++)
		{
				for(int fi=1;fi<=n-sa;fi++)
				{
						int la = fi + sa;
						for(int medi=fi;medi<=la-1;medi++)
						{
								m[fi][la] = min(m[fi][la],m[fi][medi] + m[medi+1][la] + p[fi-1]*p[medi]*p[la]  );
						}
						
				}
		}

		cout << m[1][n] << endl;
}

C++: /******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

//return the cost
int cal(int a[],int i, int j){
    if(i==j) return 0;
    int min = 1<<30;
    //printf("%d\n",min);
    for(int k = i; k<j; k++){
        int count = cal(a, i, k)+cal(a,k+1, j)+a[i-1]*a[k]*a[j];
        if(count<min) min = count;
    }
    
    return min;
}

int main()
{
    int n;
    scanf("%d",&n);
    int x[n+2], y[n+2];
    int dp[n+1][n+1];
    for(int i = 1; i<=n; i++){
        scanf("%d %d",&x[i],&y[i]);
    } x[n+1] = y[n];
    
    printf("%d\n",cal(x, 2,n+1));
    return 0;
}

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

using namespace std;
static const int N = 100;


void solve(vector<int> &data)
{
	vector<vector<int> > dp(N + 1, vector<int>(N + 1, 0));

	int nums = data.size() - 1;
	for (int len = 2; len <= nums; ++len)
	{
		for (int l = 1; l <= nums - len + 1; ++l)
		{
			int r = l + len - 1;
			dp[l][r] = INT_MAX;
			for (int m = l; m <= r - 1; ++m)
			{
				cout << len << " " << l << " " << r << endl;
				dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + data[l - 1] * data[m] * data[r]);
			}
		}
	}

	cout << dp[1][nums] << endl;
}

int main()
{
	int num; cin >> num;
	vector<int> data(num + 1);
	for (int i = 1; i <= num; ++i)
		cin >> data[i-1] >> data[i];

	solve(data);
}