Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	m := make([][]int, n)
	sizes := make([][]int, n)
	for i := 0; i < n; i++ {
		sizes[i] = []int{nextInt(), nextInt()}
		m[i] = make([]int, n)
	}
	// fmt.Println(sizes)

	for w := 1; w < n; w++ {
		for i := 0; i < n-w; i++ {
			j := i + w
			minBetweenIandJ := 10000000
			for k := i; k < j; k++ {
				// fmt.Println(i, j, k, m[i][k], m[k+1][j], sizes[i][0]*sizes[k][1]*sizes[j][1])
				minBetweenIandJ = min(minBetweenIandJ, m[i][k]+m[k+1][j]+sizes[i][0]*sizes[k][1]*sizes[j][1])
			}
			m[i][j] = minBetweenIandJ
		}
	}
	// for i := 0; i < len(m); i++ {
	// 	fmt.Println(stringifyArray(m[i]))
	// }
	fmt.Println(m[0][n-1])
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int n;
int r[110];
int c[110];
int dp[110][110];


signed main(){
    cin >> n;
    rep(i, 0, n) cin >> r[i] >> c[i];

    rep(i, 0, n) rep(j, 0, n) if(i != j) dp[i][j] = INF;
    rep(l, 1, n) rep(i, 0, n-l) rep(j, i, i+l) chmin(dp[i][i+l], dp[i][j]+dp[j+1][i+l]+r[i]*c[j]*c[i+l]);

    cout << dp[0][n-1] << endl;

    return 0;
}

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

void MatrixChain(int, int[], int **, int **);
void print(int, int, int **);

int main()
{
    int n;
    cin >> n;
    int *tempP = new int[2 * n]; //p[0]为A1的行数；p[i]为Ai的列数
    
    int *p = new int[n + 1];    //p[0]为A1的行数；p[i]为Ai的列数
    int **m = new int *[n + 1]; //m[i][j]为Ai连乘到Aj的最少乘次数
    int **s = new int *[n + 1]; //s[i][j]为 Ai连乘到Aj的最优解的第一层断点
    for (int i = 1; i <= n; i++)
    {
        m[i] = new int[n + 1];
        s[i] = new int[n + 1];
    }
    
    for (int i = 0; i < 2 * n; i++)
    {
        cin >> tempP[i];
    }
    
    for (int i = 0; i <= n; i++)
    {
        p[i] = i == 0 ? tempP[0] : tempP[i*2-1];
    }
    
    // for (int i = 0; i <= n; i++)
    //     cin >> p[i];
    MatrixChain(n, p, m, s);
    cout    << m[1][n] << endl; //最优值存储在m[1][n]
        //print(1, n, s);
    
//    for (int idx = 1; idx <= n; idx++)
//    {
//        for (int jdx = 1; jdx <= n; jdx++)
//        {
//            cout << m[idx][jdx] << " ";
//        }
//        cout << endl;
//    }
    return 0;
}

void MatrixChain(int n, int p[], int **m, int **s)
{
    int i, j, k, temp;
    //以下双重循环对m[][]的上三角进行填表
    //填表顺序为自底向上，自左向右
    for (i = n; i >= 1; i--) //i表示行
    {
        for (j = i; j <= n; j++) //j表示列，因为只填上三角，所以j的初值为i
        {
            //以下按照矩阵连乘问题的递归公式来求每一个m[i][j]
            if (i == j)
            {
                m[i][j] = 0;
            }
            else
            {
                m[i][j] = m[i][i] + m[i + 1][j] + p[i - 1] * p[i] * p[j]; //若i与j不相等，m[i][j]的初值为断点为i时的最优值
                
                s[i][j] = i;                //记录当前断点位置为i
                for (k = i + 1; k < j; k++) //k用于尝试不同的断点
                {
                    temp = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
                    if (temp < m[i][j]) //当前k值作为Ai连乘到Aj的断点能获得更少计算量
                    {
                        m[i][j] = temp; //刷新最优值
                        s[i][j] = k;    //刷新相应断点
                    }
                }
            }
        }
    }
}

void print(int i, int j, int **s)
{
    if (i == j)
        cout << "A" << i;
    else
    {
        cout << "(";
        print(i, s[i][j], s);
        print(s[i][j] + 1, j, s);
        cout << ")";
    }
}

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

int main(){
    int n, p[101], c[101][101], k; 
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> p[i-1] >> p[i];
    }
    for (int i=1; i<=n; i++) {
        c[i][i] = 0;
    }
    for (int i=2; i<=n; i++) {
        for (int j=1; j<=n-i+1; j++) {
            k = j + i -1;
            c[j][k] = 2147483647;
            for (int l=j; l <=k-1; l++) {
            c[j][k] = min(c[j][k], c[j][l] + c[l+1][k] + p[j-1]*p[l]*p[k]);
            }
        }
    }
    cout << c[1][n] << endl;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const int INF = 1001001001;

int main() {
    int n;
    cin  >> n;
    vector<int> p(n+1);
    int temp;
    for(int i=0; i<n-1; i++) {
        cin >> p[i] >> temp;
    }
    cin >> p[n-1] >> p[n];
    
    vector<int> a(n);
    vector< vector<int> > A(n,a);
    for(int i=0; i<n; i++) A[i][i] = 0;

    for(int l=2; l<=n; l++) {
        for(int i=0; i<n-l+1; i++) {
            int j = i+l-1;
            A[i][j] = INF;
            for(int k=i; k<j; k++) {
                int q = A[i][k] + A[k+1][j] + p[i]*p[k+1]*p[j+1];
                if(q<A[i][j]) A[i][j] = q;
            }
        }
    }

    cout << A[0][n-1] << endl;
    return 0;
}