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>
using namespace std;

int arr[100];
int dp[100][100];

int findNumOperation(int l, int r)
{
    if(dp[l][r] != -1) return dp[l][r];
    if(r-l==1) return 0;
    else if(r-l==2) return arr[l]*arr[l+1]*arr[r];

    int mn = 99999999;
    for(int i=l+1; i<r; i++){
        int a = findNumOperation(l,i);
        int b = findNumOperation(i,r);
        int c = a+b+(arr[l]*arr[i]*arr[r]);
        if(c<mn) mn=c;
    }
    return mn;
}

int main()
{
    int n;
    cin >> n;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            dp[i][j] = -1;
        }
    }
    cin >> arr[0] >> arr[1];
    for(int i=2; i<n+1; i++) {
        int a,b;
        cin >> a >> b;
        arr[i] = b;
    }
    int ans = findNumOperation(0, n);
    cout << ans << endl;
}

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

using namespace std;

struct matrix {
  int r;
  int c;
};

int main() {
  vector<matrix> mat;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    matrix m = {tmp1, tmp2};
    mat.push_back(m);
  }
  
  int** memo = new int*[n];
  for (int s = 0; s < n; s++) {
    memo[s] = new int[n];
  }

  for (int l = 1; l < n; l++) {
    for (int s = 0; s < n; s++) {
      if (s + l >= n) {
        break;
      }
      
      int minval = 1000000000;
      int sum = 0;
      for (int i = 0; i < l; i++) {
        sum = memo[s][s+i] + memo[s+i+1][s+l];
        matrix m1 = mat[s];
        matrix m2 = mat[s+i];
        matrix m3 = mat[s+l];

        sum += m1.r * m2.c * m3.c;

        minval = min(minval, sum);
      }
      memo[s][s+l] = minval;
    }
  }

  cout << memo[0][n-1] << endl;
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define INF (99999999)
int main(){

  //-------データの入力------------
  int n;
  cin >> n;
  int row[n];
  int column[n];
  for(int i = 0; i < n; i++){
    cin >> row[i] >> column[i];
  }
  //-----------------------------

  //[始点][終点（始点+幅）]の最小コスト
  int dp[n][n];

  //INFで初期化
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      dp[i][j] = INF;
    }
  }

  //幅0はコスト0
  //dp[i][i+0] = 0
  for(int i = 0; i < n; i++){
    dp[i][i] = 0;
  }

  //幅:j = 0 から探索開始
  for(int j = 0; j < n; j++){
    //始点: i
    for(int i = 0; i < n - j; i++){
      //仕切りを置く位置: k
      // (M_0, M_1, M_2, M_3) | (M_4, M_5)
      for(int k = i + 1; k <= i + j; k++){
        //現在のdp[i][i+j]より小さければ更新
        dp[i][i+j] = min(dp[i][i+j], dp[i][k-1] + dp[k][i+j] + row[i] * column[k-1] * column[i+j]);
      }
    }
  }
  /*
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  //始点０、幅n-1の最小コスト=> n個の行列の連鎖の計算に最低限必要な乗算の回数　を出力
  cout << dp[0][n-1] << endl;
  return 0;
}

C++: // 連鎖行列積 問題
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 100
#define ELE_NUM 2
// 無効な値の定義
const int INV = -1;

const int colNo = 0;
const int rowNo = 1;
const int IntMAX = 	2147483647;

int ChainedMatrixtMultiplication(int n, int m, int matrixData[][ELE_NUM]);

int main(void)
{

    int n, count;
    int matrix_data[MAX_N + 1][ELE_NUM];

    cin >> n;

    for(int i = 1; i <= n; i++)
    {
        // 行
        cin >> matrix_data[i][colNo];
        // 列
        cin >> matrix_data[i][rowNo];
    }

    count = ChainedMatrixtMultiplication(n, ELE_NUM, matrix_data);
    printf("%d\n", count);

    return 0;
}

// 連鎖行列積の最小の乗算回数を演算する関数
// n : 積を求める行列の数
// m : 行列の情報 : 0 - 行の情報, 1 - 列の情報
// matrixData[][] : 各行列の行、列情報を保持する配列
int ChainedMatrixtMultiplication(int n, int m, int matrixData[][ELE_NUM])
{

    // 第1要素 : 演算開始のNo., 第2要素 : 演算終了のNo.
    int dp[MAX_N + 1][MAX_N + 1];
    int calcResult = 0;

    // 配列の初期化
    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            // 無効値の代入
            dp[i][j] = INV;

            if( i == j )
            {
                // 同じ要素同士の積は演算することが不可能
                dp[i][j] = 0;
            }
        }
    }

    // 行列の演算回数の計算
    // i : 演算対象の先頭の要素No.
    // j : 演算対象の最後の要素No.
    // k : i 〜 jまでの範囲を移動する変数
    // l : 演算対象とする行列の数 ( 2 〜 n 個まで )
    for(int l = 2; l <= n; l++)
    {
        for(int i = 1; i <= n - l + 1; i++)
        {
            int j = i + l - 1;
            // 最小値を求めるために, 仮に最大値を入れておく
            dp[i][j] = IntMAX;

            for(int k = i; k <= j - 1; k++)
            {
                // 要素が2つの時は, 式の後半の部分のみで演算する
                calcResult = dp[i][k] + dp[k + 1][j]
                            + ( matrixData[i][colNo] * matrixData[k][rowNo] * matrixData[j][rowNo]);

                dp[i][j] = min( dp[i][j], calcResult );
            }
        }
    }

    return dp[1][n];
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

int n;
vector<int> d;
int dp[102][102];

void solve() {
    for (int i = 0; i < n; ++i) {
        dp[i][i] = 0;
    }
    for (int span = 2; span <= n; ++span) {
        for (int i = 0; i <= n - span; ++i) {
            int j = i + span - 1;
            dp[i][j] = INT_MAX;
            for (int k = i; k <j ; ++k) {
                dp[i][j] = min(dp[i][j], d[i] * d[j+1] * d[k+1] + dp[i][k] + dp[k+1][j]);
            }
        }
    }
}

int main() {
    cin >> n;
    d.resize(n + 1);
    int r, c;
    for (int i = 0; i < n; ++i) {
        cin >> r >> c;
        d[i] = r;
    }
    d[n] = c;
    solve();
    cout << dp[0][n-1] << endl;

    return 0;
}