Go: package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	P := make([]int, n+1)
	for i := 1; i <= n; i++ {
		l := nextInt(sc)
		P[i-1] = l
		m := nextInt(sc)
		P[i] = m
	}

	matrix := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		matrix[i] = make([]int, n+1)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n - l + 1; i++ {
			j := i + l - 1
			matrix[i][j] = (1 << 21)
			for k := i; k <= j-1; k++ {
				matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k+1][j] + P[i-1] * P[k] * P[j])
			}
		}
	}
	fmt.Println(matrix[1][n])
}

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

int n;
int num[101][101];
int p[101];

void matrixChainMultiplication(){
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      num[i][j]=INT_MAX;
      for(int k=i;k<=j-1;k++)
	num[i][j]=min(num[i][j],num[i][k]+num[k+1][j]+p[i-1]*p[k]*p[j]);
    }   
  }
  cout<<num[1][n]<<endl;
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++) cin>>p[i-1]>>p[i];
 
  for(int i=1;i<=n;i++)num[i][i]==0;
  
  matrixChainMultiplication();
      
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#define INT_MAX 100000000
using namespace std;
int sentinel;
int Mi[1000][1000];

void calc(int p[]);

int main(){
  int p[1000],a,b;
  scanf("%d",&sentinel);
  for(int i=0;i<sentinel;i++){
    scanf("%d %d",&a,&b);
    p[i] = a;
    if(i == sentinel-1)p[i+1] = b;
  }

  sentinel = sentinel+1;
  calc(p);

  printf("%d\n",Mi[1][sentinel-1]);
  return 0;
}

void calc(int p[]){
  int n = sentinel-1,j,q,l,k;
  for(int i=1;i<=n;i++)Mi[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      j = i+l-1;
      Mi[i][j] = INT_MAX;
      for(int k=i;k<=j-1;k++){
        q = Mi[i][k] + Mi[k+1][j] + p[i-1]*p[k]*p[j];
        if(q<Mi[i][j]){
          Mi[i][j] = q;
        }
      }
    }
  }
}

C++: #include<iostream>
#include<algorithm>
using namescape 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;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 <vector>
#include <algorithm>
using namespace std;

#define INF 1e9

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

  vector<int> c(n+1);
  cin >> c[0] >> c[1];
  for(int i=2; i<n+1; i++)
    cin >> temp >> c[i];

  vector< vector<int> > dp(n, vector<int>(n+1, INF));
  for(int i=0; i<n; i++)
    dp[i][i+1] = 0;
  
  for(int i=2; i<n+1; i++)
    for(int j=0; j<n; j++)
      for(int k=1; k<i; k++)
	if(j+i < n+1)
	  dp[j][j+i] = min(dp[j][j+i],
			   dp[j][j+k]+dp[j+k][j+i]+c[j]*c[j+k]*c[j+i]);
  
  cout << dp[0][n] << endl;
  
  return 0;
}

C++: // ALDS1_10_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector<int> r(110);
vector<int> c(110);
int inf=pow(10,9);
vector<vector<int>> dp(110,vector<int>(110,inf));
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    
    int n;
    cin>>n;
    rep(i,n) cin>>r[i]>>c[i];
    rep(i,n) dp[i][i]=0; //長さ1の計算量
    for(int L=2;L<=n;L++){ //長さ 短い長さからdpテーブルを埋めていく
        for(int i=0;i<=n-2;i++){ //始点
            int j=i+L-1; //終点
            if(n-1<j) break; //範囲オーバー 
            for(int k=i;k<=j-1;k++){ //i~k,k+1~jで区切る。区切ったブロックの長さは互いにL以下なので、すでに互いのブロックの最小コストはdpテーブルにある。
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*r[k+1]*c[j]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using ll = long long;
const int inf = 1e8;

int dp[105][105];

int main() {
    int n;
    cin >> n;
    vector<int> p(n+1);
    cin >> p[0] >> p[1];
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        p[i+2] = b;
    }
    rep(i,105)rep(j,105) dp[i][j] = inf;
    rep(i,n+1) dp[i][i] = 0;
    for (int i = n-1; i >= 1; i--) {
        for (int j = i+1; j <= n; j++) {
            if (j == i+1) dp[i][j] = p[i-1]*p[i]*p[i+1];
            else {
                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;
}

C++: #include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

#define INFTY 2000000000

int p[100], c[105][105];

void solve( int n ){

    int i, j, k, l;

    for( i = 1; i <= n; i++ ) c[i][i] = 0;

    for( l = 2; l <= n; l++ ){

        for( i = 1; i <= n - l + 1 ; i++ ){

            j = i + l - 1;

            c[i][j] = INFTY;

            for( k = i; k <= j - 1; k++ ){

                c[i][j] = min( c[i][j], c[i][k] + c[k+1][j] + p[i-1] * p[k] * p[j] );

            }

        }

    }

}


int main(){

    int n, i, trash;

    scanf("%d", &n);

    for( i = 1; i <= n; i++ ){

        scanf("%d %d", &p[i-1], &p[i] );

    }

    solve(n);

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

}