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 <bits/stdc++.h>

#define int             long long
#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

int dp[101][101];

signed main(){
    int N; cin >> N;
    vector<int> p( N + 1 );
    REP( i, N ){
        cin >> p[i] >> p[i + 1];
    }

    for( int l = 2; l <= N; l++ ){
        for( int i = 1; i <= N - l + 1; i++ ){
            int j = i + l - 1;
            dp[i][j] = INF;
            for( int k = i; k <= j - 1; 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;
}

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

void fnInput(vector<int>& rvnMtrx)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMtrx.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; ++i)
    cin >> rvnMtrx[i] >> rvnMtrx[i + 1];
}

int fnMtrxChainMultpl(vector<vector<int>>& rvvnDetDP, const vector<int>& cnrvnMtrx)
{
  const int nMAXSIZ = cnrvnMtrx.size() - 1;
  for (int i = 1; i <= nMAXSIZ; ++i)  rvvnDetDP[i][i] = 0;

  for (int nDif = 1; nDif <= nMAXSIZ - 1; ++nDif)
    for (int nRow = 1; nRow <= nMAXSIZ - nDif; ++nRow)
    {
      int nCol = nRow + nDif;
      for (int nx = nRow; nx <= nCol - 1; ++nx)
        rvvnDetDP[nRow][nCol] =
          min(rvvnDetDP[nRow][nCol],
              rvvnDetDP[nRow][nx] + rvvnDetDP[nx + 1][nCol] 
                                  + cnrvnMtrx[nRow - 1] * cnrvnMtrx[nx] * cnrvnMtrx[nCol]);
    }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnDetDP; 
  vector<int> vnMtrx;

  fnInput(vnMtrx);
  vvnDetDP.resize(vnMtrx.size(), vector<int>(vnMtrx.size(), INT_MAX));

  fnMtrxChainMultpl(vvnDetDP, vnMtrx);
  cout << vvnDetDP[1][vnMtrx.size() - 1] << endl;
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> R, C;
	int r, c;
	R.push_back(0);
	for (int i = 0; i < n; ++i) {
		cin >> r >> c;
		R.push_back(r);
	}
	R.push_back(c);

	int cost[100+1][100+1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			cost[i][j] = INT_MAX;
	for (int i = 1; i <= n; ++i)
		cost[i][i] = 0;

	for (int j = 1; j <= n - 1; ++j) {
		for (int i = 1; i <= n - j; ++i) {
			for (int k = i + 1; k <= i + j; ++k) {
				cost[i][i+j] = min(cost[i][i+j], cost[i][k-1] + cost[k][i+j] + R[i]*R[k]*R[i+j+1]);
			}
		}
	}

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

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int inf = INT32_MAX;

int main() {
  int n;
  cin >> n;
  V<int> column;

  rep(i, n) {
    int r, c;
    cin >> r >> c;
    if(i == 0) {
      column.push_back(r);
    }
    column.push_back(c);
  }

  V<V<int>> dp(n + 1, V<int>(n + 1));
  rep(i, n + 1) {
    dp[i][i] = 0;
  }

  int len = 2;
  while(len <= n) {
    for(int i = 1; i + len - 1 <= n; i++) {
      int j = i + len - 1;

      int min_cost = inf;
      for(int k = i; k < j; k++) {
        int cost = dp[i][k] + dp[k + 1][j] + column[i - 1] * column[k] * column[j];
        min_cost = min(min_cost, cost);
      }

      dp[i][j] = min_cost;
    }
    len++;
  }

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

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    vector<pair<int, int>> m(n);
    int a, b;
    rep(i, n) {
        cin >> a >> b;
        m[i] = make_pair(a, b);
    }
    vector<vector<int>> dp(n, vector<int>(n, INF));
    rep(i, n) dp[i][i] = 0;
    for (int len = 1; len <= n; len++) {
        for (int i = 0; i < n; i++) {
            int j = i + len - 1;
            if (j >= n)
                continue;
            for (int k = i; k < j; k++) {
                chmin(dp[i][j], dp[i][k] + dp[k + 1][j] +
                                    m[i].first * m[k].second * m[j].second);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>

using namespace std;


int main(){

  int n;
  cin >> n;
  int m[n + 1][n + 1], p[n + 1];

  for(int i = 0; i < n; i++){
    cin >> p[i] >> p[i + 1];
    m[i][i] = 0;
  }
  m[n][n] = 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] = 1000000;
      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;

  return 0;
}