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<stdio.h>

#define N 101

int main(){
  int n;
  int p[N];
  int m[N][N];
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d%d",&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;
      /*2<<21*/
      m[i][j]=2097152;
      for(int k=i;k<=j-1;k++){
	/*さいしょう比較*/
	if(m[i][j]<m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
	
	  m[i][j]=m[i][j];
	else
	  m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }
    }
  }
  printf("%d\n",m[1][n]);
  
  return 0;


  }

C++: #include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
using qi = queue<int>;
using Graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

ll dp(int* r, int* c, int n) {
    ll table[n][n];
    REP(i, n) table[i][i] = 0;
    FOR(i, 1, n) {
        REP(j, n-i) {
            table[j][j+i] = table[j][j+i-1] + r[j]*c[j+i-1]*c[j+i];
            FOR(k, j, j+i) {
                table[j][j+i] = min(table[j][k] + r[j]*c[k]*c[j+i] + table[k+1][j+i], table[j][j+i]);
            }
        }
    }
    return table[0][n-1];
}

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

    int n; cin >> n;
    int r[n], c[n];
    REP(i, n) {
        cin >> r[i] >> c[i];
    }

    // a に含まれる n 個の値で k を作ったときの最大値は何か
    int table = dp(r, c, n);

    cout << table << "\n";
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_B
// Dynamic Programming - Matrix Chain Multiplication
// TODO: review

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>
#include <memory>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const ui64 MAX_N = 100;
// dp[i][j] [i, j]までの行列をかけたときの最小コスト
int dp[MAX_N + 1][MAX_N + 1];
int p[MAX_N + 1];

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

    // initialization
    for (int i = 1; i <= n; ++i) dp[i][i] = 0;

    for (int l = 2; l <= n; ++l) {
        for (int i = 1; i <= n - l + 1; ++i) {
            auto j = i + l - 1;
            dp[i][j] = 1 << 21;
            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[k] * p[j]);
        }
    }

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

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

long long dp[105][105];
pair<int,int> p[105];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) dp[i][j]=2e9;
    for(int i=0;i<n;i++) {cin>>p[i].first>>p[i].second;dp[i][i]=0;}
    for(int i=0;i < n;i++){
        for(int j=i;j < n;j++){
            for(int k=i;k<j;k++){
                dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i].first*p[k].second*p[j].second);
            }
        }
    }
    for(int i=0;i < n;i++){
        for(int j=i;j < n;j++){
            for(int k=i;k<j;k++){
                dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i].first*p[k].second*p[j].second);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

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

int nlist[110];
int dp[110][110];

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> nlist[i] >> nlist[i+1];
  }
  for(int i = 1; i < n; i++){
    for(int j = 0; j < n - i; j++){
      dp[j][j+i] = 1 << 30;
      for(int k = 0; k < i; k++){
	    dp[j][j+i] = min(dp[j][j+i], dp[j][j+k] + dp[j+k+1][j+i] + nlist[j] * nlist[j+k+1] * nlist[j+i+1]);
      }
    }
  }
  cout << dp[0][n-1] << endl;
  return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int minana(int a,int b){
  if(a<b){
    return a;
  }
  else if(a>b){
    return b;
  }
  else return a;
}


int main(){
  int n;
  cin>>n;
  int r[100];
  int m[101][101];
  int j;
  int q=0;
  //int c[n];
  for(int i=1;i<=n;i++){
    cin>>r[i-1]>>r[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;k++){
	q=m[i][k]+m[k+1][j]+r[i-1]*r[k]*r[j];
	m[i][j]=minana(m[i][j],q);
      }
    }
  }
  
  cout<<m[1][n]<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int solve(vector<vll> &c, vector<pii> &m, int s, int e1) {
  int e = e1 - 1;
  if (c[s][e1] != 0) return c[s][e1];
  
  if (e1 - s == 2) {
    c[s][e1] = m[s].first * m[s].second * m[e].second;
    return c[s][e1];
  }

  ll n_calc = LLONG_MAX;
  for (int i = s + 1; i < e1; i++) {
    ll total = 0;
    
    if (i - s > 1) {
      c[s][i] = solve(c, m, s, i);
      total += c[s][i];
    }
    
    if (e1 - i > 1) {
      c[i][e1] = solve(c, m, i, e1);
      total += c[i][e1];
    }

    total += m[s].first * m[i].first * m[e].second;
    
    n_calc = min(n_calc, total);
  }

  c[s][e1] = n_calc;
  return c[s][e1];
}

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

  vector<pii> m(n);
  rep(i, n) cin >> m[i].first >> m[i].second;

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<vll> c(n + 1, vll(n + 1, 0));
  cout << solve(c, m, 0, n) << endl;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[101][101],p[101];

int main(){
	int i,n,j,k,l;
	cin >> n;
	for( i = 0; i < n; i++ ){
        cin >> p[i] >> p[i+1];
	}
	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 << 21);
            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]);
            }
        }
	}
	cout << dp[1][n] << endl;
}

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

using namespace std;
static const int N = 100;

#define INT_MIN     (-2147483647 - 1) /* minimum (signed) int value */
#define INT_MAX       2147483647    /* maximum (signed) int value */

void solve(vector<int> &data)
{
	vector<vector<int> > dp(N + 1, vector<int>(N + 1, 0));

	int nums = data.size() - 1;
	for (int len = 2; len <= nums; ++len)
	{
		for (int l = 1; l <= nums - len + 1; ++l)
		{
			int r = l + len - 1;
			dp[l][r] = INT_MAX;
			for (int m = l; m <= r - 1; ++m)
			{
				dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + data[l - 1] * data[m] * data[r]);
			}
		}
	}

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

int main()
{
	int num; cin >> num;
	vector<int> data(num + 1);
	for (int i = 1; i <= num; ++i)
		cin >> data[i-1] >> data[i];

	solve(data);
}