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

int M[101][101] = {};
int p[101];

int matrixChain(int n)
{
    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] = std::numeric_limits<int>::max();

            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 M[1][n];
}

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

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

    cout << matrixChain(n) << endl;

    return 0;
}

C++: #include<iostream>
#include<cassert>
using namespace std;
struct mat
{
	int w;
	int h;
};
typedef struct mat mat_t;
int mulnum(mat_t,mat_t);
long long min(long long a,long long b);

int n;
mat_t a[101];
long long dp[101][101] ;

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i].h >> a[i].w;
	}
	for(int x = 0;x<n;x++){
		for(int y =0;y<n;y++){
			dp[x][y] = 2000000;
			if(x == y) dp[x][y] = 0;
		}
	}
	int i = 0;
	int j = 1;
	for(int l = 1;l<n;l++){
		i = 0;
		for(j=l;j<n;j++){
			for(int k = i;i <= k && k < j;k++){
				dp[i][j] = min(dp[i][j],dp[i][k] + dp[k+1][j] + a[i].h *a[k].w * a[j].w);
			}
			i++;
		}
	}
	/*
	for(int x = 0;x<n;x++){
		for(int y=0;y<n;y++){
			cerr << dp[x][y] << " ";
		}
		cerr << endl;
	}
	*/
	cout << dp[0][n-1] << endl;
}

int mulnum(mat_t a,mat_t b){
	assert(a.h == b.w);
	return a.h*a.w*b.h;
}

long long min(long long a,long long b) {
	return a<b? a:b;
}

C++: #include <string>
#include <utility>
#include <iostream>
 
#define MAX 100

#define INF 100000000

int left[MAX];
int right[MAX];

int DP[MAX][MAX];

int main(){
  int n;
  std::cin >> n;

  for(int i = 0; i < n; i++){
    std::cin >> left[i];
    std::cin >> right[i];
  }
  
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      DP[i][j] = INF;
   }
  }

  for(int k = 0; k < n; k++){
    for(int l = 0; l + k < n; l++){
      int r = l + k;
      
      if(k == 0){
	DP[l][r] = 0;
      }else if(k == 1){
	DP[l][r] = left[l] * right[l] * right[r];
      }else{
	for(int t = l; t < r; t++){
	 
	  DP[l][r] = std::min(DP[l][r], DP[l][t] + DP[t + 1][r] + left[l] * right[t] * right[r]);
	}

	// printf("%d %d %d\n", l, r, DP[l][r]);
      }
    }
  }
  
  std::cout << DP[0][n - 1] << std::endl;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
static const int A=100;
int main(){
    int n,p[A+1],m[A+1][A+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 j=2; j<=n; j++){
        for(int i=1;i<=n-j+1;i++){
        int l=i+j-1;
        m[i][l]=(1<<21);
        for(int x=i;x<=l-1;x++){
            m[i][l]=min(m[i][l],m[i][x]+m[x+1][l]+p[i-1]*p[x]*p[l]);
        }
        }
    }
cout<<m[1][n]<<endl;
return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  // 初期化
  int n;
  cin >> n;
  int m[110][110];
  int p[110];
  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;
}

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

   return0;
}

C++: #include<stdio.h>

int matrixChainOrder(int *p);
int m[101][101];
int n1;
int main(){
  
  int i,r,c,min;
  int p[100];
  scanf("%d",&n1);

  for(i=0;i<n1;i++){
    scanf("%d %d",&r,&c);
    if(i==n1-1) p[n1]=c;
    p[i]=r;
  }

  min = matrixChainOrder(p);
  printf("%d\n",min);

  return 0;
}

int matrixChainOrder(int *p){
  int n2,l,i,j,q,k;
  
  n2 = n1 - 1;
  for(i=1;i<=n2;i++){
    m[i][i] = 0;
  }
  for(l=2;l<=n2;l++){ 
    for(i=1;i<=n2-l+1;i++){ 
      j = i+l-1;
      m[i][j] = 1.0/0.0;
      for(k=i;k<j;k++){
	q = m[i][k] + m[k+1][j]+p[i-1]*p[k]*p[j];
        if(m[i][j]>=q)  m[i][j] = q;
      }
    }
  }
  return m[i][j];
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define N (100)

int main(void){
    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=0;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 <stdio.h>

#define MAX_N 100
#define INF 1e8

int main(){
  int N,i,j,k,l,q,r[MAX_N],c[MAX_N],p[MAX_N+1];
  int dp[MAX_N+1][MAX_N+1];
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d%d",&r[i],&c[i]);
  }
  p[0] = r[0];
  for(i = 1 ; i <= N ; i++){
    p[i] = c[i-1];
  }
  N++;
  for(i = 0 ; i < N ; i++){
    dp[i][i] = 0;
  }
  for(l = 2 ; l < N ; l++){
    for(i = 1 ; i < N-l+1 ; i++){
      j = i + l - 1;
      dp[i][j] = INF;
      for(k = i ; k <= j-1 ; k++){
        q = dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j];
        if(q < dp[i][j]){
          dp[i][j] = q;
        }
      }
    }
  }
  printf("%d\n",dp[1][N-1]);
  return 0;
}