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<bits/stdc++.h>
#define rep(i,n) for(int i=0;i< (n);i++)
using namespace std;
typedef long long ll;
const int INF = (1e+9)+7;

int main(){
    int n;cin>>n;
    vector<vector<int>> C(n+1,vector<int>(n+1,0));
    //↑pの為に一つ多く作った。index番号が行列の番号と一致。
    vector<int> p(n+1);
    rep(i,n){
        int a,b;cin>>a>>b;
        if(i == 0){
            p[0] = a;
            p[1] = b;
        }else{
            p[i+1] = b;
        }
    }
    for(int l = 2;l<=n;l++){
        //lは行列の個数.
        for(int i = 1; i+l-1 <= n; i++){
            int j = i+l-1;//左端のindex
            int mn = INF;
            for(int k = i;k<j;k++){
                mn = min(mn,C[i][k]+C[k+1][j]+p[i-1]*p[k]*p[j]);
            }
            C[i][j] = mn;
        }
    }
    cout<<C[1][n]<<endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>



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

int main(){
  int n, p[101], m[101][101], i, j, k, l;
  cin >> n;
  for(i = 1;i <=n;i++){
    cin >> p[i-1] >> p[i];
  }

  for(i = 1;i <= n;i++) m[i][i] = 0;
  for(l = 1;l <= n;l++){
    for(i = 1;i <= n - l + 1;i++){
      j = i + l - 1;
      m[i][j] = (1 << 21);
      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]);
      }
    }
  }

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

  return 0;
}

C++: #include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

int N;
vector<int> R, C;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  R.resize(N);
  C.resize(N);
  rep(i, N) { cin >> R[i] >> C[i]; }

  int dp[N][N + 1];
  rep(i, N) { fill(dp[i], dp[i] + N + 1, 0); }

  for (int i = 2; i <= N; i++) {
    for (int l = 0; l < N; l++) {
      int r = l + i;
      if (r > N) {
        continue;
      }
      dp[l][r] = INF;
      for (int k = l + 1; k < r; k++) {
        dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + R[l] * R[k] * C[r - 1]);
      }
    }
  }
  cout << dp[0][N] << endl;
  return 0;
}

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

const int N=100;

int main(){
	int n;
	long m[N+1][N+1], p[N+1];
	
	scanf(" %d", &n);
	for(int i=1; i<=n; ++i)
		scanf(" %ld %ld", &p[i-1], &p[i]);
		
	//for(int i=0; i<=n; ++i) printf("p[%d]=%ld\n", i, p[i]);
		
	for(int i=1; i<=n; ++i) m[i][i]=0;
	
	for(int s=2; s<=n; ++s){ //s??????????????????
		for(int i=1; i+s-1<=n; ++i){ //?§????i
			int j=i+s-1; //??????j
			m[i][j]=100000000; //????????§???????????§?????????
			for(int k=i; k<=j-1; ++k){ //?????????k
				m[i][j]=min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
				//printf("go %d %d %d\n",i, j, k);
			}
		}
	}
	
	printf("%ld\n", m[1][n]);
}

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 ( 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>
#include <cstdlib>
#include <vector>
using namespace std;

struct matrix_size{
	int row;
	int col;
};

int matrixchaincost(vector <matrix_size> &M){
	int n=M.size();
	vector < vector <int> > cost(n, vector <int> (n));
	vector < vector <matrix_size> > X(n, vector <matrix_size> (n));
	for (int i=0; i<n; i++){
		cost[i][i] = 0;
		X[i][i] = M[i];
	}

	for (int length=2; length<=n; length++){
		for (int i=0; i+length<=n; i++){
			int j = i+length-1;
			X[i][j].row = X[i][i].row;
			X[i][j].col = X[j][j].col;
			if (X[i][j-1].col != X[j][j].row){
				cout<<"error"<<endl;
				return NULL;
			}
			int k = i+1;
			int mincost = X[i][k-1].row * X[i][k-1].col * X[k][j].col + cost[i][k-1] + cost[k][j];
			k++;
			while (k<=j){
				int tmp = X[i][k-1].row * X[i][k-1].col * X[k][j].col + cost[i][k-1] + cost[k][j];
				if (tmp<mincost)
					mincost = tmp;
				k++;
			};
			cost[i][j] = mincost;
		}
	}
	return cost[0][n-1];
}

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

	vector <matrix_size> M(n);

	for (int i=0; i<n; i++){
		cin>>M[i].row;
		cin>>M[i].col;
	}
	cout<<matrixchaincost(M);
	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;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int r[100];
int c[100];
int dp[100][100];
int main(void){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> r[i] >> c[i];
  }

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

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