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

#define MAX_SIZE (110)
int P[MAX_SIZE];
int M[MAX_SIZE][MAX_SIZE];

int main()
{
  int N;
  std::cin >> N;
  for (int i = 1; i <= N; ++i)
  {
    std::cin >> P[i - 1] >> P[i];
  }

  for (int i = 0; i <= N; ++i) M[i][i] = 0;
  for (int n = 2; n <= N; ++n)
  {
    for (int i = 1; i <= N - n + 1; ++i)
    {
      int j = i + n - 1;
      M[i][j] = 1 << 30;
      for (int k = i; k < j; ++k)
      {
        M[i][j] = std::min(M[i][j], M[i][k] + M[k + 1][j] + P[i - 1] * P[k] * P[j]);
      }
    }
  }

  std::cout << M[1][N] << std::endl;

  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	int p[101], m[101][101];
	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][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	cout<<m[1][n]<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using DoP = pair<double, double>;
using edge = struct { int to; double cost;}; // edge x = {to, cost}

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1<<29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int n;
vector<P> x;
vector<vector<ll>> dp;

ll rec(int l = 0, int r = n) {
  if(r-l <= 1) dp[l][r] = 0;
  if(r-l==2) dp[l][r] = x[l].first*x[l].second*x[l+1].second;
  if(dp[l][r] != INF64) return dp[l][r];
  for(int mid = l+1; mid < r; ++mid) chmin(dp[l][r], rec(l, mid)+rec(mid, r)+x[l].first*x[mid].first*x[r-1].second);
  return dp[l][r];
}

int main(){
  cin >> n;
  x.resize(n);
  dp.assign(n+1, vector<ll>(n+1, INF64));
  rep(i, n) cin >> x[i].first >> x[i].second;
  cout << rec() << endl;
}

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

using namespace std;

class MatrixMultipluCost{
private:
 vector<unsigned long> p;
 vector< vector<unsigned long> > cost;

public:
 MatrixMultipluCost(unsigned long num)
  : p(num+1, 0), cost(num+1, vector<unsigned long>(num+1, 0)){

  for(unsigned long mat_i = 0; mat_i < num; ++mat_i){
   unsigned long tmp_row = 0; cin >> tmp_row;
   if(mat_i == 0) p[mat_i] = tmp_row;
   unsigned long tmp_col = 0; cin >> tmp_col; p[mat_i+1] = tmp_col;
  }

 };

 unsigned long colculateCost(void){
 unsigned long matrixNum = p.size()-1;

  for(unsigned long distance = 1; distance < matrixNum; ++distance){
   for(unsigned long front_i = 1; front_i+distance <= matrixNum; ++front_i){
    for(unsigned long rear_i = front_i; rear_i < front_i+distance; ++rear_i){
     unsigned long tmp_cost = cost[front_i][rear_i] + cost[rear_i+1][front_i+distance] + p[front_i-1] * p[rear_i] * p[front_i+distance];
     if(cost[front_i][front_i+distance] == 0 || cost[front_i][front_i+distance] > tmp_cost) cost[front_i][front_i+distance] = tmp_cost;
    }
   }
  }

  return cost[1][matrixNum];
 };

 void display(){
  for(unsigned long i = 0, max = p.size(); i < max; ++i)
   cout << p[i] << " ";
  cout << endl;

  for(unsigned long i = 0, max = cost.size(); i < max; ++i){
   for(unsigned long j = 0; j < max; ++j){
    cout << cost[i][j] << " ";
   }
   cout << endl;
  }
 };

};

int main(){
 unsigned long num = 0; cin >> num;

 MatrixMultipluCost MMC(num);
 cout << MMC.colculateCost() << endl;


 return 0;
};

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[111][111],n,L[111],R[111];
int f(int l,int r){
	if(dp[l][r]>-1)return dp[l][r];
	int res=1e9;
	for(int i=l;i<r;i++){
		res=min(res,f(l,i)+f(i+1,r)+L[l+1]*R[i]*R[r]);
	}
	return dp[l][r]=res;
}
main(){
	memset(dp,-1,sizeof(dp));
	r(i,111)dp[i][i]=0;
	cin>>n;
	r(i,n)cin>>L[i]>>R[i];
	cout<<f(0,n-1)<<endl;
}