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

static const int N = 100;

int main() {

	int n, p[N + 1], m[N + 1][N + 1];

	scanf("%d", &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]);
				}
			}
		}

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

		return 0;
	}

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

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

  vector< vector<int> > dp(n + 1, vector<int>(n + 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] = 1000000000;
      for (int k = i; k < j; ++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>
#define MAX 100001
#define SENTINEL 2000000000
using namespace std;

int m[101][101];
int p[101];

void mcm()
{
}

int main()
{
    int n;
    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] = MAX;
            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 <algorithm>
#include <climits>
#define INF INT_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    int m[n+1][n+1], p[n+1];
    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] = INF;
            for(int k = i; k < j; k++){
                int q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
                m[i][j] = min(m[i][j], q);
            }
        }
    }

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

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n+1);
    rep(i, n) {
        int r, c;
        cin >> r >> c;
        if (i == 0) {
            a[i] = r;
            a[i+1] = c;
        } else {
            a[i+1] = c;
        }
    }

    vvi dp(n+1, vi(n+1, INF));
    for (int i = 1; i <= n; ++i) dp[i][i] = 0;
    // kが間隔
    for (int k = 1; k <= n - 1; ++k) {
        // iが始点
        for (int i = 1; i + k <= n; ++i) {
            // jが間の点
            for (int j = i; j <= i + k - 1; ++j) {
                chmin(dp[i][i+k], dp[i][j] + dp[j+1][i+k] + a[i-1]*a[j]*a[i+k]);
            }
        }
    }

    // for (int i = 1; i <= n; ++i) {
    //     for (int j = i+1; j <= n; ++j) {
    //         for (int k = i; k <= j-1; ++k) {
    //             chmin(dp[i][j], dp[i][k] + dp[k+1][j] + a[i-1] * a[k] * a[j]);
    //         }
    //     }
    // }
    // だと更新順がダメ
    
    cout << dp[1][n] << endl;
}

C++: #include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<string>
//#define MAX 101
#define INFTY (1<<21)

using namespace std;

static const int N = 100;


/*int min(int a, int r[], int c[]) {



	for(int i=1; i<=a; i++){
		if(r[i] == c[i+1]){
			int s = r[i]*c[i]*r[i+1];
		}
}*/

int main() {
	int n;
	

	int M[N+1][N+1];
	int p[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 j = 2; j <= n; j++) {
		for (int i = 1; i <= n - j + 1; i++) {
			int k = i + j - 1;

			M[i][k] = INFTY;

			for (int a = i; a <= k - 1; a++) {
				int b = M[i][a] + M[a + 1][k] + p[i - 1] * p[a] * p[k];
				M[i][k] = min(M[i][k], b);

			}
		}
	}

	cout << M[1][n] << endl;
	/*int R[MAX];
	int C[MAX];

	int r, c;
	for(int i = 1; i<=n; i++){
		cin >> r >> c;
		R[i] = r;
		C[i] = c;

	}*/

	return 0;
}

C++: #include<bits/stdc++.h>
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++: #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 = 0;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++: #include <bits/stdc++.h>
using namespace std;

constexpr int INF = (1 << 30) - 1;

int memo[105][105];
int n; 
int r[105], c[105];

int dfs(int left, int right)
{
    int ret = INF;
    if ( left == right ) return ( 0 );
    if ( memo[left][right] != -1 ) return ( memo[left][right] );
    for ( int i = left; i < right; i++ ) { 
        ret = min(ret, dfs(left, i) + dfs(i + 1, right) + r[left] * c[right] * c[i]);
    }
    return ( memo[left][right] = ret );
}

int main()
{
    fill_n(*memo, 105 * 105, -1);

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> r[i] >> c[i];
    }

    cout << dfs(0, n - 1) << endl;

    return ( 0 );
}