Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for 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])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int n;
int m[200][200];
int p[200];

int matrixChainMultiplication(){
    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] = 1001001001;
            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]);                
            }
        }
    }
    return m[1][n];
}

int main() {
    cin >> n;
    rep(i, n){
        int a, b; cin >> a >> b;
        p[i] = a;
        p[i+1] = b;
    }
    int ans = matrixChainMultiplication();

    cout << ans << endl;

    return 0;
}

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

#define M 100

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

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;
const int INF = 1e+9;

const int N = 100;
int n;
int s[N+1];       //M_i : s[i-1] x s[i] (i=1,...,n)
int dp[N+1][N+1]; //dp[i][j] = (M_i * ... * M_j)????????????????¨?????????°???????°????(1<=i<=j<=n)

int main() {
  int i, j, k, l;
  scanf("%d ", &n);
  for (i=0; i<n; i++) scanf("%d%d ", s+i, s+i+1);
  for (i=1; i<=n; i++) dp[i][i] = 0;  //1????????????????¨?????????°???0
  for (l=2; l<=n; l++)  //M_i ... M_i????????°???????????§????????????
    for (i=1; i<=n-l+1; i++) {
      j = i + l - 1; 
      dp[i][j] = INF;
      for (k=i; k<j; k++)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s[i-1]*s[k]*s[j]);
    }

  printf("%d\n", dp[1][n]);

  return 0;
}

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

#define N_MAX 105
#define INF (1 << 21)

long P[N_MAX];
long dp[N_MAX][N_MAX];

int main() {
    long n;
    cin >> n;
    for (long i = 0; i < n; i++) {
        cin >> P[i] >> P[i + 1];
    }

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

    for (long l = 1; l <= n - 1; l++) {
        for (long i = 1; i + l <= n; i++) {
            long j = i + l;
            dp[i][j] = INF;
            for (long k = i; k <= j; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + P[i - 1] * P[j] * P[k]);
            }
        }
    }

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

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
struct RC {
    int r, c;
};

int dp[101][101];
int main()
{
    int N;
    cin >> N;
    vector<RC> rc(N);
    rep(i, N) {
        int r, c;
        cin >> r >> c;
        rc[i] = {r, c};
    }

    vector<vector<int>> dp(N, vector<int>(N, 1e9));
    rep(i, N) dp[i][i] = 0;

    repd(w, 1, N) {
        rep(i, N - w) {
            int j = i + w;
            repd(k, i, j) {
                chmin(dp[i][j], dp[i][k] + dp[k + 1][j] + rc[i].r * rc[k].c * rc[j].c);
            }
        }
    }

    cout << dp[0][N - 1] << endl;
    return 0;
}

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

#define N 101

vector<vector<int> > dp(N, vector<int>(N));
int p[N+1];

// dp[i][j] := [Mi, Mj]におけるminimum number of scalar multiplications 

int main(){
    
    int n;
    cin >> n;
    
    for (int i = 1; i < n+1; i++) cin >> p[i-1] >> p[i];
    
    
    // l はchain lengthを表す変数である.
    // l == 1のとき計算回数は0である.
    for (int l = 2; l <= n; l++){
        
        // 変数iは区間の左端を表す
        // 左端が動ける範囲の上限は, n - l + 1である
        // 具体例を考えてみよ
        for (int i = 1; i <= n-l+1; i++){
            
            // jは右端の上限値を表す
            int j = i + l - 1;
            
            dp[i][j] = (1<<20);
            
            // 今回調べる区間は, [i, j-1]
            for (int k = i; k < j; 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 <stdio.h>

int N;
int R[200];
int dp[200][200];

int min(int x, int y) { return x < y ? x : y; }

int main(void) {
	scanf("%d", &N);
	for (int i = 0; i < N; i ++) {
		scanf("%d %d", &R[i], &R[i+1]);
	}
	for (int i = 0; i < N; i ++) {
		for (int j = 0; j < N; j ++) {
			dp[i][j] = 1 << 20;
		}
	}
	for (int i = 0; i < N; i ++) {
		dp[i][0] = 0;
	}
	for (int j = 0; j < N; j ++) {
		for (int i = 0; i + j < N; i ++) {
			// M_j ... M_{j+i}のi+1個の積について考える
			for (int k = 0; k < j; k ++) {
				// (M_j ... M_{j+k}) (M_{j+k+1} ... M_{j+i})
				//   (k+1個の積)            (i-k個の積)
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[i+k+1][j-k-1] + R[i] * R[i+k+1] * R[i+j+1]);
			}
		}
	}
	printf("%d\n", dp[0][N-1]);
	return 0;
}