Go: package main

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

const N = 100

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

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, N+1)
	m := make([][]int, N+1)
	for i := range m {
		m[i] = make([]int, N+1)
	}
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 1; i <= n; i++ {
		scanner.Scan()
		p[i-1], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		p[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 1; i <= n; i++ {
		m[i][i] = 0
	}
	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i+l-1
			m[i][j] = 1 << 21
			for 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])
			}
		}
	}
	fmt.Println(m[1][n])
}

C++: #include <iostream>
#include <stdio.h>
//#include <string.h>

using namespace std;

struct Matrix{
    int row;
    int col;
    int total;
};

Matrix mts[100][100];
int n;

int main()
{
    scanf("%d",&n);
    for(int i=0; i<n; ++i){
        int r,c;
        scanf("%d %d", &r, &c);
        mts[0][i].row = r;
        mts[0][i].col = c;
        mts[0][i].total = 0;
    }

    for(int i=1; i<n; ++i){
        for(int j=0; j<n-i; ++j){
            int min = 0xfffffff;
            mts[i][j].row = mts[i-1][j].row;
            mts[i][j].col = mts[0][i+j].col;
            for(int k=0; k<i; ++k){
                int tmp = mts[k][j].total + mts[i-k-1][k+j+1].total + mts[k][j].row * mts[i-k-1][k+j+1].row * mts[i-k-1][k+j+1].col;
                min = min < tmp ? min : tmp;
            }
            mts[i][j].total = min;
        }
    }

    cout << mts[n-1][0].total << endl;

    return 0;
}

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

using namespace std;


int main()
{
    int n;
    int p[101];
    int m[101][101];

    cin >> n;

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            m[i][j] = 0;

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

    for (int len = 1; (n - 1) - len >= 0; len++) {
        for (int i = 0; i <= (n - 1) - len; i++) {
            m[i][i + len] = INT_MAX / 3;
            for (int j = i; j < i + len; j++) {
                m[i][i + len] = min(m[i][i + len], m[i][j] + m[j + 1][i + len] + p[i] * p[j + 1] * p[i + len + 1]);
            }
        }
    }

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

    return 0;
}

C++: #include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //???????????\??¢??°
#include <fstream> //ifstream, ofstream

//#define NDEBUG //NDEBUG???#include <cassert>???????????????????????????????????´???assert?????????????????????????????????NDEBUG?????????????????????????????????????????????
#include <cassert> //assert


using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************
//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
//??????????????????????????????????????????????????????????§?CPU???????£??????????????????§???TLE?????????????????????????????????????????§????????¨???                           ????????????????????????cerr????????£????????????????????????????????????
#ifdef TEST
#define dout cout
#define din cin
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif

//?¨??????????????????????????????????????????????????????´??????OUTPUTFILE????????????????????¬???????????????????????????????????¢????????????
//#define OUTPUTFILE "output.txt" //*******************************************************************************************************************************************
#ifdef OUTPUTFILE
#define dout outputfile //??¨????????????TLE????????§?????????dout?????¨??¨??????????????¢????????????????????????????????????????????§????¨????????????´??????????????£??????????????????????¨?????????????????????????????????????????????§?????????????????????
ofstream outputfile(OUTPUTFILE);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif

//?¨??????\???????????????????????????????????????????????´??????INPUTFROMTEXTFILE????????????????????¬???????????????????????????????????¢????????????
//#define INPUTFILE "input.txt" //*******************************************************************************************************************************************
#ifdef INPUTFILE
#define din inputfile
ifstream inputfile(INPUTFILE);
#endif


#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << setw(3) << (A) << " " // << setw(3) ??????????????\????????????
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef unsigned long long ll;

const int INF = 1e9-1;

int N;
int R[101];
int C[101];

int solve(int n, int r[], int c[]) {
    if(n==1) return 0;
    
    if(n==2) {
        assert(c[0]==r[1]);
        return r[0]*c[0]*c[1];
    }
    
    int min = INF;
    int tmp;
    rep(i,0,n-1) {
        
        //M[i]*M[i+1]?????????????????¨??????r[],c[]?????????
        int rr[n-1], cc[n-1];
        rep(j,0,n-1) {
            if(j<i) {
                rr[j] = r[j];
                cc[j] = c[j];
            }
            else if(j==i) {
                rr[j] = r[i];
                cc[j] = c[i+1];
            }
            else {
                rr[j] = r[j+1];
                cc[j] = c[j+1];
            }
        }
        
        //M[i]*M[i+1]?????????????´???°???1????????£???n-1??¨?????£?????????????????°???????§£???
        //????????????ans???M[i]*M[i+1]????¨?????????°??????????????????
        assert(c[i]==r[i+1]);
        tmp = solve(n-1, rr, cc) + r[i]*c[i]*c[i+1];
        
        if(tmp<min) min = tmp;
    }
    
    assert(min!=INF);
    return min;
}


int main() {
    din >> N;
    rep(i,0,N) {
        din >> R[i] >> C[i];
    }
    
    dout << solve(N, R, C) << endl;
    
    
#ifdef INPUTFILE
    inputfile.close();
#endif
    
#ifdef OUTPUTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}