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<string>
#include<algorithm>
#include<cstdio>
using namespace std;

static const int N = 100;



int main(void) {
	int n, p[N + 1], m[N + 1][N + 1];

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &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]);
			}
		}
	}

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

	return 0;
}

C++: #include <stdio.h>
  
#define INF 10000000
  
int main(){
  int n,i,j,k,l,t,m[101],c,o;
  int mm[101][101];
   
   
  scanf("%d",&n);
  for(i = 1 ; i < n+1; i++){
    scanf("%d%d",&m[i-1],&m[i]);
  }
   
for( i = 1 ; i <= n ; i++ ){
    mm[i][i] = 0;
  }  
   
  for(l = 2 ; l <n+1 ; l++){
    for(i=1;i<n-l+2;i++) {
        o=i+l-1;
    mm[i][o] = INF;
   
    for(k = i ; k < o ; k++){
t=mm[i][k] + mm[k+1][o] + m[i-1] * m[k] *m[o];
 
        if(t < mm[i][o])
          mm[i][o] = t;
        }
      }
    }
  printf("%d\n",mm[1][n]);
  return 0;
  }

C++: #include <algorithm>
#include <iostream>
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;
}

C++: #include<iostream>
#include<vector>
#define NIL -1
using namespace std;

struct M{
    int r;
    int c;
};

int calc(int s, int e, const vector<M>& M_set,
         vector<vector<int> >& MEMO) {
    if (s == e) return MEMO[s][e] = 0;
    if (MEMO[s][e] != NIL) return MEMO[s][e];
    int min = 1e9;
    for (int split = s; split < e; split++) {
        int val = calc(s, split, M_set, MEMO)
                  + calc(split + 1, e,M_set, MEMO)
                  + M_set[s].r * M_set[split].c * M_set[e].c;
        if (min > val) min = val;
    }
    return MEMO[s][e] = min;
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > MEMO(n, vector<int>(n, NIL));
    vector<M> M_set(n);
    for (int i = 0; i < n; i++) {
        cin >> M_set[i].r >> M_set[i].c;
    }
    cout << calc(0, n - 1, M_set, MEMO) << endl;
    return 0;
}

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


int main(void){
  int i, j, k, l;
  int n, mat[100+1][100+1], len[100+1];

  scanf("%d", &n);
  
  for(int i=1; i<=n; i++){
    scanf("%d %d", &len[i-1], &len[i]);
  }
  
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      mat[i][j]=INT_MAX;

      for(k=i; k<=j-1; k++){
	mat[i][j]=min(mat[i][j], mat[i][k]+mat[k+1][j]+len[i-1]*len[k]*len[j]);
      }
    }
  }

  printf("%d\n", mat[1][n]);
  
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;

int n;
int shape[N_MAX][2];
int dp[N_MAX][N_MAX];

int mcm() {
    FOR(d,0,n) {
        FOR(from,0,n-d) {
            int to = from + d;
            if (from == to) {
                dp[from][to] = 0;
            } else {
                int minval = -1;
                FOR(s,0,d) {
                    int cand = dp[from][from+s] + dp[from+s+1][to]
                        + shape[from][0] * shape[from+s][1] * shape[to][1];
                    if (minval == -1) {
                        minval = cand;
                    } else {
                        minval = min(cand, minval);
                    }
                }
                dp[from][to] = minval;
            }
        }
    }
    return dp[0][n-1];
}

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

    cin >> n;
    FOR(i,0,n) {
        cin >> shape[i][0] >> shape[i][1];
    }
    cout << mcm() << endl;

    return 0;
}

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

int CountMulti(const int& r1,const int& c1,const int& r2,const int& c2){
	return c1*c2*r1;
}

int main(void){
	int N;
	cin >> N;
	vector<long long> rows(N),cols(N);
	for(int i=0;i<N;i++)
		cin >> rows[i] >> cols[i];

	const long long INF = 1e18;
	long long dp[101][101];
	memset(dp,0,sizeof(dp));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i == j)dp[i][j] = 0;
			else dp[i][j] = INF;
		}
	}
	for(int i=0;i<N-1;i++){
		dp[i][i+1] = rows[i]*rows[i+1]*cols[i+1];
	}

	for(int d=2;d<N;d++){
		for(int l=0;l<N-d;l++){
			for(int r=l;r<l+d;r++){
				dp[l][l+d] = min(dp[l][l+d], dp[l][r] + dp[r+1][l+d] + rows[l]*rows[r+1]*cols[l+d]);
			}
		}
	}
	cout << dp[0][N-1] << endl;
	return 0;
}

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

using P = pair<int, int>;

int nmul(int x, int y, int z){
    return x*y*z;
}

int main(){
    int n; cin >> n;
    vector<int> M(n+1);
    int dummy;
    for(int i=0; i<n; ++i){
        cin >> M[i] >> dummy;
    }
    M[n] = dummy;
    vector<vector<int>> dp(n+1, vector<int>(n+1, numeric_limits<int>::max()));
    // dp[i][i+l] = M_i から M_{i+l} までの行列乗算の最適コスト
    for(int l=0; l<n; ++l) dp[l][l] = 0;

    for(int L=1; L<n; ++L){
        for(int l=0; l<n-L; ++l){
            for(int k=0; k<L; ++k){
                dp[l][l+L] = min(dp[l][l+L], dp[l][l+k] + dp[l+k+1][l+L] + nmul(M[l],M[l+k+1],M[l+L+1]));
            }
        }
    }
    cout << dp[0][n-1] << endl;
}