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 <algorithm>
#include <iostream>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_N = 100;

struct matrix {
    int r;
    int c;
};

ll dp[MAX_N + 1][MAX_N + 1];

ll solve(const int i, const int j, const vector<struct matrix> &matrices) {
    if (j <= i) return 0;
    if (j - i == 1) return matrices[i].r * matrices[i].c * matrices[j].c;
    if (dp[i][j] != LONG_LONG_MAX / 2) return dp[i][j];

    ll answer = LONG_LONG_MAX / 2;
    for (int k = i; k < j; k++) {
        chmin(answer, solve(i, k, matrices) + solve(k + 1, j, matrices) + matrices[i].r * matrices[k].c * matrices[j].c);
    }

    dp[i][j] = answer;
    return answer;

    // for (int i = 1; i <= N; i++) {
    //     int j = i + 1;
    //     dp[i][j] = matrices[i].r * matrices[i].c * matrices[j].c;
    //     j++;
    //     for (; j <= N; j++) {
    //         for (int k = i + 1; k < j; k++) {
    //             chmin(dp[i][j], dp[i][k] + dp[k + 1][j] +
    //                     matrices[i].r * matrices[k].c * matrices[j].c);
    //         }
    //     }
    // }
    // 
    // return dp[1][N];
}

int main(void) {
    int N;
    cin >> N;
    vector<struct matrix> matrices(N + 1);

    for (int i = 1; i <= N; i++) {
        cin >> matrices[i].r >> matrices[i].c;
    }

    for (int i = 1; i <= MAX_N; i++) {
        for (int j = i + 1; j <= MAX_N; j++) {
            dp[i][j] = LONG_LONG_MAX / 2;
        }
    }

    cout << solve(1, N, matrices) << endl;

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= N; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    
    return 0;
}

C++: #include <cstdio>

#define N 10000

typedef long long int lli;

lli a[N*N];
lli b[N*N];
lli c[N*N];

int n,m,l;

void mult() {
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            for(int k=0; k<m; k++)
                c[i*N + j] += a[i*N + k] * b[k*N + j];
}

int main(void) {
    scanf("%d%d%d",&n,&m,&l);

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            scanf("%lld", &a[i*N + j]);
    for(int i=0; i<m; i++)
        for(int j=0; j<l; j++)
            scanf("%lld", &b[i*N + j]);
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            c[i*N + j] = 0;

    mult();

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<l-1; j++)
            printf("%lld ", c[i*N + j]);
        printf("%lld", c[i*N + l-1]);
        printf("\n");
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define 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 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=l+i-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 <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll n;
V< P<ll, ll> > rc;
vvll dp;

ll rec(ll l, ll r) {
    if (l == r) return dp[l][r] = 0;
    if (dp[l][r] != HIGHINF) return dp[l][r];
    for (ll i = l; i <= r - 1; i++) {
        chmin(dp[l][r], rec(l, i) + rec(i + 1, r) + rc[l].first * rc[i].second * rc[r].second);
    }
    return dp[l][r];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rc.resize(n);
    for (ll i = 0; i < n; i++) cin >> rc[i].first >> rc[i].second;
    dp.resize(n, vll(n, HIGHINF));
    cout << rec(0, n - 1) << '\n';

    // for (ll i = 0; i < n; i++) DEBUG_VLL(dp[i])
    return 0;
}

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

const int INF = 1 << 28;

int n;
int memo[101][101];
int r[102];

int dfs(int i, int j){
    int res = INF;
    
    if(memo[i][j] != -1) return memo[i][j];
    
    if(i == j){
        return 0;
    }
    
    for(int k = i; k < j; ++k){
        res = min(res, dfs(i,k) + dfs(k + 1, j) + r[i] * r[k + 1] * r[j + 1]);    
    }
    
    return memo[i][j] = res;
}


int main()
{

    cin >> n;
    fill((int*)memo, (int*)(memo + n), -1);
    for(int i = 0; i < n; ++i){
        cin >> r[i] >> r[i + 1];
    }
    
    cout << dfs(0, n-1) << endl;
    
}

C++: #include<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define _USE_MATH_DEFINES // M_PI????????????????????????
#include<math.h>
#pragma warning(disable:4996)
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][k],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	cout << m[1][n] << "\n";
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1010;

int p[N];

int f[N][N];

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)	scanf("%d%d", &p[i - 1], &p[i]);
	
	for(int len = 2; len <= n; len++)
	{
		for(int i = 1; i + len - 1 <= n; i++)
		{
			int j = i + len - 1;
			
			f[i][j] = INF;
			
			for(int k = i; k < j; k++)
			{
				f[i][j] = min(f[i][j], f[i][k] + f[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	
	
	printf("%d\n", f[1][n]);
	
	return 0;
}