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 <iostream>
#include <algorithm>
using namespace std;

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 ( 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 <iostream>
#define NMAX 100
#define MAX 100000000
using namespace std;

struct Matrix{
  long long r;
  long long c;
};

Matrix m[NMAX];
int n;

long long minmulti_[NMAX][NMAX];

long long minmulti(int begin,int end){
  if(begin==end){return 0;}
  if(begin+1==end){return m[begin].r*m[begin].c*m[end].c;}
  if(minmulti_[begin][end]!=0) return minmulti_[begin][end];
  long long min=MAX;
  long long num;
  for(int i=begin;i<end;i++){
     num = minmulti(begin,i) + minmulti(i+1,end);
     num += m[begin].r*m[i].c*m[end].c;
     if(num<min){min=num;}
  }
  minmulti_[begin][end]=min;
  return min;
}

int main(){
  for(int i=0;i<NMAX;i++){
    for(int j=0;j<NMAX;j++){
      minmulti_[i][j]=0;
    }
  }
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>m[i].r>>m[i].c;
  }
  cout<<minmulti(0,n-1)<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    long long p[n + 1];
    for (int i = 0; i < n; i++)
    {
        cin >> p[i] >> p[i + 1];
    }
    long long m[n + 1][n + 1];
    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; 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<iostream>
#include<climits>
#include<utility>
#include<algorithm>
#include<cstring>

using namespace std;

long long calc_min_cost(pair<int, int>*, int);

int main() {
	int n,mini;
	cin >> n;
	pair<int, int>* mat = new pair<int, int>[n];
	for (int i = 0;i < n;i++) {
		cin >> mat[i].first >> mat[i].second;
	}
	if (n == 1) {
		cout << "0\n";
		return 0;
	}
	int** first_last = new int* [n];
	for (int i = 0;i < n;i++) {
		first_last[i] = new int[n - i];
		first_last[i][0] = 0;
	}
	for (int i = 1;i < n;i++) {
		for (int j = 0;j < n - i;j++) {
			mini = INT_MAX;
			for (int k = 0;k < i;k++) {
				mini = min(mini, first_last[j][k] + first_last[j + k + 1][i - k - 1] + mat[j].first * mat[j + k].second * mat[j + i].second);
			}
			first_last[j][i] = mini;
		}
	}
	cout << first_last[0][n - 1] << endl;
}

long long calc_min_cost(pair<int, int>* mat, int n) {
	pair<int, int> *tmp = new pair<int,int>[n];
	long long cost=-1, mini = INT_MAX;
	if (n == 2) {
		return mat[0].first * mat[0].second * mat[1].second;
	}
	for (int i = 0;i < n-1;i++) {
			cost = (long long)(mat[i].first) * mat[i].second * mat[i+1].second;
			memcpy(tmp, mat, sizeof(pair<int,int>) * n);
			tmp[i].second = tmp[i+1].second;
			for (int j = i+1;j < n-1;j++) {
				tmp[j] = tmp[j + 1];
			}
			cost += calc_min_cost(tmp, n - 1);
			mini = min(mini, cost);
	}
	free(tmp);
	return mini;
}

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

typedef long long ll;
#define inf 1e9+7

int n;
ll dp[102][102];
ll p[102];

void init(){
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]=inf;
        }
        dp[i][i]=0;
    }
}

void cal(int l, int r){
    if(l>=r)return;
    if(dp[l][r]<inf)return;
    for(int k=l;k<r;k++){
        cal(l,k);
        cal(k+1,r);
        dp[l][r] = min(dp[l][r], dp[l][k]+dp[k+1][r]+p[l]*p[k+1]*p[r+1]);
    }
}

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

    cin >> n;
    init();
    cin >> p[0] >> p[1];
    ll a,b;
    for(int i=1;i<n;i++){
        cin >> a >> b;
        p[i+1]=b;
    }
    cal(0,n-1);
    cout << dp[0][n-1] << endl;
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
        int n;
        cin>>n;
        int r[n], c[n], a[n][n];
        for(int i=0;i<n;i++) cin>>r[i]>>c[i];
        for(int i=0;i<n;i++)
                a[i][i] = 0;

        for(int i=1;i<n;i++){
                for(int j=0;j+i<n;j++){
                        a[j][j+i] = 2000000000;
                        for(int k=0;k+1<=i;k++)
                                a[j][j+i] = min(a[j][j+i], a[j][j+k]+a[j+k+1][j+i] + r[j]*c[j+k]*c[j+i]);
                }
        }
        cout<<a[0][n-1]<<endl;
        return 0;
}

C++: #include <iostream> 
#include <cmath> 
 
using namespace std; 
 
int r[45] = {0}; 
int a[100][100] = {0}; 
 
int f(int n, int m); 
int f(int n, int k, int m); 
 
 
int f(int n, int k, int m) 
{ 
    return f(n,k) * f(k+1,m) + (r[n] * r[k+1] * r[m+1]); 
} 
 
int f(int n, int m) 
{ 
    if (n==m) return 1; 
    int & ra = a[n][m]; 
    if (ra) return ra; 
    ra = INT_MAX; 
    for (int k=n;k<m;k++) 
    { 
        int ans = f(n,k,m); 
        if (ans < ra) ra = ans; 
    } 
    return ra; 
} 
 
int main() 
{ 
    int rr = 0; 
    int cc = 0; 
    int n = 0; 
    cin >> n; 
    for (int i=0;i<n;i++) 
    { 
        cin >> rr >> cc; 
        r[i]=rr; 
        r[i+1]=cc; 
    } 
    for (int i=0;i<n-1;i++) 
    { 
        a[i][i+1] = r[i] * r[i+1] * r[i+2]; 
    } 
    int ans = f(0,n-1); 
    cout << ans << endl; 
}

C++: #include<iostream>
#include<algorithm>
#define MAX 100
#define INF (1 << 30)
using namespace std;

int n, p[103], m[102][102];

int matrixChainMultiplication(void);

int main() {
	int i;

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

	cout << matrixChainMultiplication();

	return 0;
}

int matrixChainMultiplication(void) {
	int i, j, k;
	for (i = 1; i <= n; i++)m[i][i] = 0;
	for (j = 2; j <= n; j++) {
		for (i = j - 1; i >= 1; i--) {
			m[i][j] = INF;
			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]);
			}
		}
	}
	return m[1][n];
}

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

static const in N = 100;

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

  for(int i = 0;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++){
      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<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;
}