Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		fmt.Scan(&a[i+1])
	}

	m := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		m[i] = make([]int, n+1)
	}

	for d := 2; d <= n; d++ {
		for s := 0; s+d <= n; s++ {
			min := 1 << 30
			for j := s+1; j < s+d; j++ {
				val := m[s][j] + m[j][s+d] + a[s]*a[j]*a[s+d]
				if val < min {
					min = val
				}
			}
			m[s][s+d] = min
		}
	}
	fmt.Println(m[0][n])
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<22;

// dp[i][j] := [i , j]??????????????????????????則???????????????????属???即????????属
// |(4*5   (5*3)  3*2)|  2*1
int main()
{
	int n, dp[128][128], r[128];
	P T[128];

	cin >> n;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
		 	dp[i][j] = INF;
		}
	}
	/*
	for(int i = 0; i < n; i++)
	{
		dp[i][i] = 0;
	}
	*/
	for(int i = 0; i < n; i++)
	{
		cin >> T[i].first >> T[i].second;
		dp[0][i] = 0;
	}
	/*
	r[0] = T[0].first;
	for(int i = 0; i < n; i++)
	{
		r[i+1] = T[i].second;
	}
	*/
	/*
	for(int i = 0; i <= n; i++)
	{
		cout << r[i] << endl
	}
	*/
	/*
	for(int l = 1; l < n; l++)
	{
		for(int i = 0; i < n-l; i++)
		{ 
			int j = i + l;
			for(int k = 1; k <= l; k++)
			{
				dp[i][j] = std::min(dp[i][j], dp[i][i + k - 1] + dp[i + k][j] + T[i].first*T[i + k].first*T[j].second); //r[j]*r[k]*r[i+j+1]);
			}
		}
	}
*/
	for(int i = 1; i < n; i++)
	{
		for(int j = 0; j < n-i; j++)
		{ 
			for(int k = 1; k <= i; k++)
			{
				dp[i][j] = std::min(dp[i][j], dp[k-1][j] + dp[i-k][j+k] + T[j].first*T[j + k].first*T[j + i].second); //r[j]*r[k]*r[i+j+1]);
				//printf("%3d : %3d : %3d => %3d\n", i, j, k, dp[i][j]);
				//puts("run");
			}
		}
	}

	/*
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			printf("%10d ",dp[i][j]);
		}
		puts("");
	}
    */	

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

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

using namespace std;

int main {

    int i, j, k, l, n, p[101], m[101][101];

    cin >> n;

    for (i = 1; i <= n; i++) {
        cin >> p[i - 1] >> p[i];
    }

    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]);
            }
        }
    }

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

    return 0;

}

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

/*
 * http://ttrsq.exblog.jp/24318687/
 */

const int MAX_N = 100;
int DP[MAX_N + 1][MAX_N + 1] = {0};
int *p;

int best(int r, int c) {
  int min = INT_MAX;
  int num = c - r;

  for (int i = 0; i < num; i++) {
    min = std::min(min, DP[r][r + i] + DP[r + i + 1][c] + p[r - 1] * p[r + i] * p[c]);
  }
  
  return min;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n = 0;
  std::cin >> n;

  if (n == 1) {
    std::cout << "0" << std::endl;
  }
  
  p = (int *) std::malloc(sizeof(int) * n + 1);

  int bb = 0;

  std::cin >> p[0];
  std::cin >> p[1];
  
  for (int i = 2; i <= n; i++) {
    std::cin >> bb;
    std::cin >> p[i];
  }

  for (int i = 1; i < n; i++) {
    DP[i][i + 1] = p[i - 1] * p[i] * p[i + 1];
  }

  for (int j = 0; j <= n - 3; j++) {
    for (int i = j + 3; i <= n; i++) {
      DP[i - 2 - j][i] = best(i - 2 - j, i);
    }
  }

  std::cout << DP[1][n] << std::endl;

  return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> p[i] >> p[i + 1];
  }
  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      if (i == j)
        dp[i][j] = 0;
      else {
        int tmp = 1e9;
        for (int k = i; k < j; k++) {
          tmp = min(tmp, dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
        }
        dp[i][j] = tmp;
      }
    }
  }
  debug(dp);
  cout << dp[1][n] << endl;
  return 0;
}

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

const int INF = 1 << 28;

int main()
{
    int n;
    int dp[101][101];
    int r[102];
    
    cin >> n;
    
    fill((int*)dp, (int*)(dp + n), INF);
    
    for(int i = 0; i < n; ++i){
        cin >> r[i] >> r[i + 1];
        dp[i][i] = 0;
    }
    
    for(int w = 1; w < n; ++w){
        for(int i = 0, j ; j = i + w, j < n; ++i){
            for(int k = i; k < j; ++k){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + r[i] * r[k + 1] * r[j + 1]);
            }
        }
    }
    
    cout << dp[0][n-1] << endl;
    
}

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

void MatrixChainMultiplication(int n,int p[],int m[101][101]) {
	int i, j, k,l;
	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]);
			}
		}
	}
}

int main() {
	int n, p[101], m[101][101];
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	MatrixChainMultiplication(n, p, m);
	cout << m[1][n] << endl;

	
}

C++: #include <bits/stdc++.h>
#define INF 1e7

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    cin >> n;
    vector<int>l(n),r(n);
    for(int i = 0; i < n; i++) cin >> l[i] >> r[i];
    vector<vector<int>>dp(n,vector<int>(n,INF));
    for(int i = 0; i < n; i++) dp[i][i] = 0;
    for(int p = 2; p <= n; p++)
    {
        for(int i = 0; i+p-1 <= n-1; i++)
        {
            int j = i+p-1;
            int S = INF;
            for(int k = i; k < j; k++) S = min(S,dp[i][k]+dp[k+1][j]+l[i]*r[k]*r[j]);
            dp[i][j] = S;
        }
    }
    cout << dp[0][n-1] << endl;
}