Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}

//solve
//単純な場合
func matrixChainMultiplication() {
	//行列が1つだけのとき
	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
			//kまでで区切る
			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])
			}
		}
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

const MAX = 100

var n int
var p [MAX + 1]int

//m[i][j]: Mi * Mi+1 * ... * Mjを計算するときに必要なスカラー乗算の最小回数
var m [MAX + 1][MAX + 1]int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 1; i <= n; i++ {

		p[i-1] = nextInt() //行数
		p[i] = nextInt()   //列数
	}

	matrixChainMultiplication()
	fmt.Println(m[1][n])
}

C++: #pragma GCC diagnostic ignored "-Wunused-variable" 
#include <bits/stdc++.h>
using namespace std;

//#define BOOST
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace boost;
using ml = boost::multiprecision::cpp_int;
using md = boost::multiprecision::cpp_dec_float_100;
#define forir(i, ...) if(ll i=(ll)v.size())for(__VA_ARGS__)if(i--,1)
#define eachr(i, e, c) forir(i, auto &&e: adaptors::reverse(c))
#endif

/***** type *****/
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
/***** define *****/
#define all(c) (c).begin(), (c).end()            // begin to end
#define coutd cout << fixed << setprecision(10)  // cout double
#define output(x) do{cout<<x;return 0;}while(0)  // cout return
#define rep(i, b, e) for (ll i = b; i < e; i++)  // repeat
#define repr(i, b, e) for (ll i = b; e < i; i--) // repeat reverse
#define fori(i, ...) if (ll i = -1) for(__VA_ARGS__) if (i++, 1)
#define each(i, e, c) fori (i, auto&& e: c)      // for each
/***** const value *****/
#define llong_max 9223372036854775807            // 9 * 10^18
#define ldbl_max 1.79769e+308                    // 1.7 * 10^308
#define pi 3.1415926535897932                    // 3.14 ...
/***** lambda *****/
auto Ceil = [] // if (a % b != 0) return a / b + 1;
(auto x) { return (ll)ceil(x); };
auto Count = [] // long long count value
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoL = [] // char to number
(auto c) { return (ll)c - (ll)'0'; };
auto LtoC = [] // number to char
(auto n) { return (char)('0' + n); };
auto Pow = [] // long long pow
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = [] // long long pow2
(auto n) { return (1LL << n); };
auto Pow10 = [] // long long pow10
(auto n) { return (ll)pow(10, n); };
auto Size = []  // long long collection size
(auto& c) { return (ll)(c).size(); };
auto Sum = [] // long long accumulate
(auto b, auto e) { return accumulate(b, e, 0LL); };

/***** template *****/
template <class T> void MakeVVT
(ll ys, ll xs, vvt<T>& v, T fill = T())
{	// vector<vector<T>> resize + fill
	v.resize(ys); rep(y, 0, ys) v[y].resize(xs, fill);
}
template <class T> void MakeVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fill = T())
{	// vector<vector<vector<T>>> resize + fill
	v.resize(zs); rep(z, 0, zs) MakeVVT(ys, xs, v[z], fill);
}
template <class T> void InputVT
(ll xs, vt<T>& v, T fix = T())
{	// input vector<T> (T != struct) + fix
	v.resize(xs); rep(i, 0, xs) { cin >> v[i]; v[i] += fix; }
}
template <class T> void InputVVT
(ll ys, ll xs, vvt<T>& v, T fix = T())
{	// input vector<vector<T>> (T != struct) + fix
	MakeVVT(ys, xs, v, fix);
	rep(y, 0, ys) rep(x, 0, xs) { cin >> v[y][x]; v[y][x] += fix; }
}
template <class T> void InputVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fix = T())
{	// input vector<vector<vector<T>>> (T != struct) + fix
	v.resize(zs); rep(z, 0, zs) InputVVT(ys, xs, v[z], fix);
}

/**************************************/
/********** BEGIN OF NYA LIB **********/
/**************************************/

namespace NyaGadget {}

/**************************************/
/*********** END OF NYA LIB ***********/
/**************************************/

using namespace NyaGadget;
//using mll = NT_ModLL< 1000000007 >;
//using mll = NT_ModLL< 998244353 >;

int main(void)
{
	ll n; cin >> n;

	vt<ll> nyaa(n+1);
	rep(i, 0, n) cin >> nyaa[i] >> nyaa[i+1];

	ll const inf = Pow10(9);
	vvt<ll> dp; MakeVVT(n, n, dp, inf);
	rep(i, 0, n) dp[i][i] = 0;
	rep(range, 1, n) rep(l, 0, n)
	{
		ll r = l + range;
		if (n <= r) continue;
		rep(m, l, r) dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + nyaa[l] * nyaa[m+1] * nyaa[r+1]);
	}
	cout << dp[0][n-1] << endl;
	return 0;
}

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

void compute(vector<vector<int> > & cost,vector<vector<int> > & best,
			 vector<int> & A,int s,int e){
	int minc = 0;
	int mink = -1;
	for(int k=s+1;k<=e;++k){
		if (cost[s][k-1] < 0){
			compute(cost,best,A,s,k-1);
		}
		if (cost[k][e] < 0) {
			compute(cost,best,A,k,e);
		}
		int c = cost[s][k-1] + A[s]*A[k]*A[e+1] + cost[k][e];
		if (mink < 0 || c < minc) {
			minc = c;
			mink = k;
		}
	}
	cost[s][e] = minc;
	best[s][e] = mink;
}

int main(){
	vector<vector<int> > cost,best;
	vector<int> A;
	int n;
	cin >> n;
	A.resize(n+1);
	for(int i=0;i<n;++i) {
		int r,c;
		cin >> r >> c;
		if (i==0){
			A[0] = r;
		}
		if (A[i] != r){ cout << "error";exit(0);}
		A[i+1] = c;
	}
	cost.resize(n);
	best.resize(n);
	for(int i=0;i<n;++i){
		cost[i].resize(n);
		best[i].resize(n);
		for(unsigned j=0;j<cost[i].size();++j){
			cost[i][j] = -1;
			best[i][j] = -1;
		}
		cost[i][i]=0;
		best[i][i]=i;
	}
	compute(cost,best,A,0,n-1);
	cout << cost[0][n-1] << std::endl;
	return 0;
}

C++: #include <iostream>
#define INF 100001
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int dp[n+1][n+1],p[n+1];
  cin >> p[0] >> p[1];
  for(int i=2;i<=n;i++){
    int t; cin >> t;
    cin >> p[i];
  }
  for(int i=1;i<=n;i++) dp[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      dp[i][j]=INF;
      for(int k=i;k<=j-1;k++)
        dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j]);
    }
  }
  cout << dp[1][n] << endl;
}

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

using namespace std;

const int MAX_N = 100;
const long long INF = 10000000000000;

long long DP[MAX_N][MAX_N];
pair<int,int> P[MAX_N];

int main()
{
	int n;
	long long q;
	cin >> n;
	for(int i=0;i<n;i++){
		scanf("%d",&P[i].first);
		scanf("%d",&P[i].second);
	}
	fill(DP[0],DP[n],INF);
	for(int i=0;i<n;i++){
		DP[i][i] = 0;
	}
	for(int l=1;l<n;l++){
		for(int i=0;i<n-l;i++){
			for(int k=i;k<i+l;k++){
				q = DP[i][k] + DP[k+1][i+l] + P[k].second * P[i].first * P[i+l].second;
				if(q < DP[i][i+l]){
					DP[i][i+l] = q;
				}
			}
		}
	}
	cout << DP[0][n-1] << "\n";
}