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 <bits/stdc++.h>
#define INF 1000000000
typedef long long ll;
using namespace std;

int main()
{
	ll n;
	cin >> n;
	vector<ll> M(n + 1);
	cin >> M[0];
	for (int i = 1; i < n; i++) {
		cin >> M[i] >> M[i];
	}
	cin >> M[n];
	vector<vector<ll>> dp(n, vector<ll>(n, INF));
	for (int i = 0; i < n; i++) {
		dp[i][i] = 0;
	}
	for (ll k = 1; k < n; k++) {
		for (ll i = 0; i + k < n; i++) {
			for (ll j = 0; j <= i + k - 1; j++) {
				ll cost = dp[i][j] + dp[j + 1][i + k] + M[i] * M[j + 1] * M[i + k + 1];
				if (cost < dp[i][i + k]) {
					dp[i][i + k] = cost;
				}
			}
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef long long ll;
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
const double PI = 3.14159265358979323846;

typedef pair<ll, ll> P;


string to_upper(string str) {
    int diff = 'a' - 'A';
    for (int i = 0; i < str.size(); i++) {
        char c = str[i];
        if ('A' <= c && c <= 'Z') {
            c += diff;
            str[i] = c;
        }
    }
    return str;
}


int main() {

    int n;
    cin >> n;


    vector<P> matrix_list(n);
    rep(i, n) cin >> matrix_list[i].first >> matrix_list[i].second;

    vector<ll> p(n + 1, 0);
    p[0] = matrix_list.front().first;
    rep(i, n) p[i + 1] = matrix_list[i].second;

    vector<vector<ll> > dp(n + 1, vector<ll>(n + 1, 0));


    for (int l = 2; l <= n; l++) {  // 行列の個数
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            ll min_cost = INF;
            for (int k = i; k < j; k++) {
                if (k == i) min_cost = dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j];
                else min_cost = min(min_cost, dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
            dp[i][j] = min_cost;
        }
    }

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

C++: #include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll n;
        cin >> n;
        vll a(n+1);

        rep(i, 1, n+1) cin >> a[i-1] >> a[i];

        //print1d(a);

        vllvll dp(110, vll(110, inf));
        rep(i, 0, 110) dp[i][i] = 0;
        
        rep(width, 2, n+1) {
            rep(left, 1, n-width+2) {
                ll right = left + width - 1;
                rep(div, left, right) {
                    chmin(dp[left][right], dp[left][div] + dp[div+1][right] + a[left-1] * a[div] * a[right]);
                }
            }
        }

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

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

long long n;
long long r[110], c[110];
vector<vector<long long>> dp(110, vector<long long>(110, -1));
long long rec(long long l, long long m){
    if(dp[l][m] != -1) return dp[l][m];
    if(l + 1 == m) return dp[l][m] = r[l] * c[l] * c[m];
    else if(l == m) return dp[l][m] = 0;
    else{
        long long ans = 1e9;
        for (long long i = l; i < m; i++)
        {
            long long len = rec(l, i) + r[l] * c[i] * c[m] + rec(i + 1, m);
            ans = min(ans , len);
        }
        return dp[l][m] = ans;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> r[i] >> c[i];
    }

    int ans = rec(0, n-1);
    cout << ans << endl;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int dp[101][101];
int r[100],c[100];
int solv(int a,int b){//a??????b-1?????§?????????????????????????????????????????°???????°???¨?????????????????????????????????
    if(dp[a][b]==-1){
        if(a == b-1){
            dp[a][b]=0;
        }else if(a==b-2){
            dp[a][b]=r[a]*c[a]*c[a+1];
        }else{
            int Pmin=999999999;
            for(int j=a+1;j<b;j++){
                int tmp=solv(a,j)+solv(j,b)+r[a]*r[j]*c[b-1];
                Pmin=min(Pmin,tmp);
            }
            dp[a][b]=Pmin;
        }
    }
    return dp[a][b];
}
int main(){
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            dp[i][j]=-1;
        }
    }
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>r[i]>>c[i];
    }
    int ans=solv(0,N);
    cout<<ans<<endl;
    return 0;
}

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=0;i<n;i++) cin >> p[i] >> p[i+1];
    for(int l=1;l<=n;l++) {
        for(int i=0;i<=n-l;i++) {
            int j = i + l;
            if(l==1) m[i][j] = 0;
            else if(l==2) m[i][j] = p[i]*p[i+1]*p[j];
            else {
                m[i][j] = 1000000000;
                for(int k=1;k<l;k++) {
                    m[i][j] = min(m[i][j], m[i][i+k] + m[i+k][j] + p[i]*p[i+k]*p[j]);
                }
            }
        }
    }
    //cout << m[4][6] << endl;
    cout << m[0][n] << endl;
    
    return 0;
}