Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	var n int
	var M [101][101]int

	n = nextInt()

	P := make([]int, n*2)

	for i := 1; i <= n; i++ {
		P[i-1] = nextInt()
		P[i] = nextInt()
	}
	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			M[i][j] = 1000000
			for k := i; k <= j-1; k++ {
				M[i][j] = int(math.Min(float64(M[i][j]), float64(M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j])))
			}
		}
	}
	fmt.Println(M[1][n])
}

C++: #include <cassert>// c
#include <iostream>// io
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>// container
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <algorithm>// other
#include <complex>
#include <numeric>
#include <functional>
#include <random>
#include <regex>
using namespace std;

typedef long long ll;typedef unsigned long long ull;typedef long double ld;

#define ALL(c) c.begin(),c.end()
template<class T> bool IN(T l,T v,T r){return l<=v && v <r;}
template<class T> void UNIQUE(T v){v.erase(unique(ALL(v)),v.end());}
//debug
#define DUMP(x) cerr << #x <<" = " << (x)
#define LINE() cerr<< " (L" << __LINE__ << ")"

// values
template<typename T> inline T INF(){assert(false);};
template<> inline int INF<int>(){return 1<<28;};
template<> inline ll INF<ll>(){return 1LL<<58;};
template<> inline double INF<double>(){return 1e16;};
template<> inline long double INF<long double>(){return 1e16;};

template<class T> inline T EPS(){assert(false);};
template<> inline int EPS<int>(){return 1;};
template<> inline ll EPS<ll>(){return 1LL;};
template<> inline double EPS<double>(){return 1e-8;};
template<> inline long double EPS<long double>(){return 1e-8;};

// min{2^r | n < 2^r}
template<typename T> T upper_pow2(T n){ T res=1;while(res<n)res<<=1;return res;}
// max{d | 2^d  <= n}
template<typename T> T msb(T n){ int d=63;while((1LL<<d)>n)d--;return d;}

template<typename T,typename U> T pmod(T v,U M){return (v%M+M)%M;}

class Main{
	public:
	void run(){
		int N;cin >> N;
		vector<int> rs(N),cs(N);
		
		for(int i=0;i<N;i++)cin >> rs[i] >> cs[i];

		vector<vector<ll>> dp(N,vector<ll>(N+1,INF<ll>()));
		for(int l=0;l<N;l++) dp[l][l+1] = 0;

		for(int d=2;d<=N;d++)for(int l=0;l+d<=N;l++){
			int r = l+d;
			for(int m=l+1;m<r;m++){
				dp[l][r] = min(dp[l][r],dp[l][m] + rs[l] * rs[m] * cs[r-1] + dp[m][r]);
			}
		}
		cout << dp[0][N] <<endl;
	}
};

int main(){
	cout <<fixed<<setprecision(20);
	cin.tie(0);
	ios::sync_with_stdio(false);
	Main().run();
	return 0;
}

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

static const int N = 200;

int main(){
    int n, p[N+1],m[N+1][N+1];
    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;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 INF 1e8;

int matrixChainMultiplication(int *p, int n) {
  int m[n+1][n+1];
  for (int i = 0; i <= n; i++) m[i][0] = 0;
  for (int j = 0; j <= n; j++) m[0][j] = 0;
  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] = INF;
      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]);
      }
    }
  }
  //上のループで、DPテーブル対角線上のゼロに近接するマスが順に埋まっていく
  //最終的に右端のm[1][n]がM1M2...Mnを計算する際の最小計算回数になる

  return m[1][n];
}

int main() {
  int n;
  cin >> n;
  int p[n+1];
  for (int i = 1; i <= n; i++) cin >> p[i-1] >> p[i];
  cout << matrixChainMultiplication(p, n) << endl;
  return 0;
}

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

static const int N=100;

int main(){
  int i,l,n,p[N+1],m[N+1][N+1];
  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-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 <iostream>
#include <vector>
#include <array>
#include <string>

const int size = 105;
const int NIL = -1;
int dp[size][size];
int ps[size];

int min_cost(int i, int j)
{
  if (dp[i][j] != NIL)
    return dp[i][j];

  int k=i;
  int min = min_cost(i,k) + min_cost(k+1,j) + ps[i-1]*ps[k]*ps[j];
  for (k=i+1; k<=j-1; ++k)
    {
      int tmp = min_cost(i,k) + min_cost(k+1,j) + ps[i-1]*ps[k]*ps[j];
      if (tmp < min) min = tmp;
    }
  dp[i][j] = min;
  return min;
}


int main()
{
  int n;
  std::cin >> n;

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

  for (int i=0; i<size; ++i)
    for (int j=0; j<size; ++j)
      dp[i][j] = NIL;

  for (int i=1; i<=n; ++i)
    {
      dp[i][i] = 0;
    }

  std::cout << min_cost(1,n) << std::endl;
}

C++: #include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

static const int N = 100;

int main() {
  int n, p[N + 1], m[N + 1][N + 1];
  cin >> n;
  REP1(i, n + 1) {
    cin >> p[i - 1] >> p[i];
  }

  REP1(i, n + 1) m[i][i] = 0;
  FOR(l, 2, n + 1) {
    REP1(i, n - l + 2) {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      FOR(k, i, j) {
        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 <algorithm>
using namespace std;

static const int N=100;

int main(){
    int n,p[N+1],m[N+1][N+1];
    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;
}

C++: #include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define endl '\n'

int n;
ll r[111],c[111],d[111];
ll dp[111][111];
const ll oo = 1000000000000000LL;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> r[i] >> c[i];
	d[0] = r[1];
	for(int i = 1; i <= n; i++)
		d[i] = c[i];
	for(int size = 1; size <= n;size++){
		for(int i = 1; i <= n - size; i++){
			int j = i + size;
			dp[i][j] = oo;
			for(int k = i; k <= j - 1;k++){
				ll cost = dp[i][k] + dp[k + 1][j] + d[i - 1]*d[k]*d[j];
				dp[i][j] = min(dp[i][j],cost);
			}
		}
	}
	
	cout << dp[1][n] << endl;

	return 0;
}

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

using namespace std;

static const int N = 100;

int main() {
    int n, P[N + 1], m[N + 1][N + 1];
    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;
}