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 <vector>
using namespace std;

typedef long long ll;
const ll inf = 1<<30;

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

    int nb; cin >> nb;
    vector<ll> dim(nb);
    int trash;
    for(auto& a:dim) cin >> a >> trash;
    dim.push_back(trash);
    
    vector<vector<ll>> cost( nb, vector<ll>(nb, inf) );
    for (int i=0; i<nb; ++i){
        cost[i][i] = 0;
    }
    
    for (int k=1; k<nb; ++k){
        for (int i=0; i+k<nb; ++i){
            for (int j=0; j<i+k; ++j){
                cost[i][i+k] = min(
                    cost[i][i+k],
                    cost[i][j] + cost[j+1][i+k] + dim[i]*dim[j+1]*dim[i+k+1]);
            }
        }
    }

    cout<<cost[0][nb-1] <<"\n";
}

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

int main(void){
    int i,n;
    cin >> n;
    int p[n+1];
    int **m = new int*[n+1];
    for(i=1; i<=n; i++){
        m[i] = new int[n+1];
    }
    for(i=1; i<=n; i++) cin >> p[i-1] >> p[i];
    for(i=1;i<=n;i++) m[i][i] = 0;
    for(int l=2; l<=n; l++){
        for(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;
    for(int i=1; i<n+1; i++){
        delete[] m[i];
        m[i] = 0;
    }
    delete[] m;
    m = 0;
    return 0;
}

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

struct TMatrixInfo
{
	int RowSize;
	int ColSize;
	TMatrixInfo(int ARowSize, int AColSize)
	{
		RowSize = ARowSize;
		ColSize = AColSize;
	}
	TMatrixInfo()
	{
	}
};

vector<vector<int> > TableResize(int n)
{
	vector<vector<int> > CostCountTable;
	CostCountTable.resize(n);
	for(int i = 0; i < n; i++){
		CostCountTable[i].resize(n);
	}
	return CostCountTable;
}

int Cost(TMatrixInfo A, TMatrixInfo B)
{
	return A.RowSize * A.ColSize * B.ColSize;
}

TMatrixInfo M(int Index1, int Index2, const vector<TMatrixInfo>& MatrixChain)
{
	TMatrixInfo Matrix(MatrixChain[Index1].RowSize, MatrixChain[Index2].ColSize);
	return Matrix;
}

int GetCellValue(const vector<vector<int> >& CostCountTable, const vector<TMatrixInfo>& MatrixChain, int Row, int Col)
{
	if(Col == Row){
		return 0;
	}else{
		int CurrentMinCost;
		for(int i = Row; i < Col; i++){
			int CurrentCost = CostCountTable[Row][i] + Cost(M(Row, i, MatrixChain), M(i+1, Col, MatrixChain)) + CostCountTable[i+1][Col];
			if(i == Row || CurrentCost < CurrentMinCost){
				CurrentMinCost = CurrentCost;
			}
		}
		return CurrentMinCost;
	}
}

void CalcSlantingLine(vector<vector<int> >& CostCountTable, const vector<TMatrixInfo>& MatrixChain, int Col)
{
	int n = MatrixChain.size();
	for(int i = 0; i < n-Col; i++){
		CostCountTable[i][Col+i] = GetCellValue(CostCountTable, MatrixChain, i, Col+i);
	}
}

int MinCalcCost(const vector<TMatrixInfo>& MatrixChain)
{
	int n = MatrixChain.size();
	vector<vector<int> > CostCountTable = TableResize(n);
	for(int i = 0; i < n; i++){
		CalcSlantingLine(CostCountTable, MatrixChain, i);
	}
	return CostCountTable[0][n-1];
}

int main()
{
	int n;
	cin >> n;
	vector<TMatrixInfo> MatrixChain(n);
	for(int i = 0; i < n; i++){
		cin >> MatrixChain[i].RowSize;
		cin >> MatrixChain[i].ColSize;
	}
	cout << MinCalcCost(MatrixChain) << endl;
	return 0;
}

C++: #define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int n; std::cin >> n;
    std::vector<int> r(n), c(n);
    for(int i(0); i < n; ++i) std::cin >> r[i] >> c[i];
    //dp[i][j] := iからjまでの計算に必要な回数
    std::vector<std::vector<int>> dp(n, std::vector<int>(n, 0));
    for(int d(1); d < n; ++d){
        for(int i(0), i_len(n - d); i < i_len; ++i){
            int j(i + d);
            dp[i][j] = INF;
            for(int k(i); k < j; ++k){
                chmin(dp[i][j], dp[i][k] + dp[k+1][j] + r[i]*c[k]*c[j]);
            }
        }
    }
    std::cout << dp[0][n-1] << std::endl;
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N;
int r[105],c[105];
ll dp[105][105]={0};

void dbg()
{
	for(int i=0;i<N;i++,puts(""))
		for(int j=0;j<N;j++)
			printf("%7d ",dp[i][j]);
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
		scanf("%d%d",&r[i],&c[i]);
	for(int i=0;i<N;i++)dp[i][i]=0;
	for(int l=1;l<N;l++)
		for(int i=0;i<N-l;i++)
		{
			int j=i+l;
			dp[i][j]=10000000;
			for(int k=0;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
		}
	dbg();
	printf("%d\n",dp[0][N-1]);
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define N 100
#define INF 1<<25
int n,p[N+1],m[N+1][N+1];
int matrixchainmultiplication(){
  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]=INF;
      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]);
      }
    }
  }
  return m[1][n];
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>p[i]>>p[i+1];
  cout<<matrixchainmultiplication()<<endl;
  return 0;
}
/*
verified on 2017/04/26
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_B
*/

C++: #include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <math.h>
#define MAX 100
void min(int,int);
int p[MAX]={},m[MAX][MAX]={};

void min(int n1,int n2){
  if(n1>n2) n1=n2;
}
    
int main()
{
  int n,r,l,i,j,k;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d %d",&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++){
	min(m[i][j],m[i][k]+m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}