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 REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dp[111][111];
int mat[111][2];

int solve(int l, int r){
    if(l + 1 >= r) return 0;
    if(dp[l][r]) return dp[l][r];

    int mi = INF;
    for(int i=l+1;i<r;++i){
        chmin(mi, solve(l, i) + solve(i, r) + mat[l][0] * mat[i][0] * mat[r-1][1]);
    }
    return dp[l][r] = mi;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    REP(i,n) cin >> mat[i][0] >> mat[i][1];
    cout << solve(0,n) << endl;
}

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

#define MAX_N 100
#define R(i) (m[2*(i)])
#define C(i) (m[2*(i)+1])

typedef int int32_t;

// ??????????¨????????????§DP???

int main(void) {
    int n;
    int m[2 * MAX_N] = {};

    int dp[MAX_N][MAX_N] = {};

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &R(i), &C(i));
    }

    for (int i = 0; i < n-1; i++) {
        dp[i][i + 1] = R(i) * C(i) * C(i+1);
    }
    for (int i = 2; i < n; i++) {
        for (int j = 0; j <= n - i; j++) {
            dp[j][i + j] = INT32_MAX;
            for (int k = 0; k < i; k++) {
                 dp[j][i + j] = min(dp[j][i + j], dp[j][j+k] + dp[j+k+1][i+j] + R(j) * R(j+k+1) * C(i+j));
            }
        }
    }

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

C++: #include <stdio.h>
#include <limits.h>
#define MAX 100

int main(){
	int n, m[MAX+1][MAX+1];
	int i, j, k, r, min;
	
	scanf("%d", &n);
	for(i=1;i<=n;++i) {
		scanf("%d %d", &m[i][i-1], &m[i+1][i]);
		m[i][i] = 0;
	}
	
	for(r=2;r<=n;++r){
		for(i=1;i<=n-r+1;++i){
			j=i+r-1;
			m[i][j] = INT_MAX;
			for(k=i;k<=j-1;++k){
				min = m[i][k]+m[k+1][j]+m[i][i-1]*m[k+1][k]*m[j+1][j];
				if(m[i][j] > min) m[i][j] = min;
			}
		}
	}
	printf("%d\n", m[1][n]);
	return 0;
}

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

using namespace std;

const int INFTY = (1<<30);

int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 1);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> A[i + 1];
    }

    vector< vector<int> > cost(N);
    cost[0].assign(N, 0);
    for (int l = 2; l < N + 1; l++)
    {
        cost[l - 1].assign(N - l + 1, INFTY);
        for (int num = 0; num < N - l + 1; num++)
        {
            for (int k = 1; k < l; k++)
            {
                cost[l-1][num] = min(
                    cost[l-1][num],
                    cost[k-1][num] + cost[l-1-k][num+k] + A[num]*A[num+k]*A[num+l]
                );
            }
        }
    }
    cout << cost[N-1][0] << endl;
}

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

static const int N = 100;

int main()
{
  int p,ppp[N+1],m[N+1][N+1];

  cin >> p;

  for( int i = 1; i <= p; i++)
    {
      cin >> ppp[i-1] >> ppp[i];
    }

  for (int i = 1; i <= p; i++) m[i][i] = 0;
  for (int k = 2; k <= p; k++)
    {
      for(int i = 1; i <= p-k+1 ; i++)
	{
	  int j = i + k - 1;
	  m[i][j] = (1 << 21);

	  for ( int q = i; q <= j-1 ; q++)
	    {
	      m[i][j] = min(m[i][j], m[i][q] + m[q+1][j] +
			      ppp[i-1] * ppp[q] * ppp[j]);
	    }
	}
    }

  cout << m[1][p] << 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=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=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] << "\n";
????????return 0;
}

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

long int M[101][101];
long int a[100];
int n;
void solve(){
  for(int i=0;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]=INT_MAX;
       	  for(int k=i;k<j;k++){
	        long int tmp = M[i][k]+M[k+1][j]+a[i-1]*a[k]*a[j];
		if(M[i][j]>tmp){
		    M[i][j] = tmp;	
		}
	    }
	}
    }
}

int main(){ 
   cin>>n;
   for(int i=0;i<n;i+=2){
	cin>>a[i]>>a[i+1];
   }
   solve();
   for(int i=0;i<=n;i++){
	for(int j=0;j<=n;j++){
//	    cout<<"("<<i<<","<<j<<")"<<M[i][j]<<" ";
	}
//	cout<<endl;
   }
   cout<<M[1][n-1]<<endl;
   return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n,a;
    cin>>n;
    int p[n+1];
    for(int i=0;i<=n;i++){
        cin>>p[i]>>p[i+1];
    }
    int m[n+1][n+1];
    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]=100000000;
            for(int k=i;k<=j-1;k++){
                int q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
                if(q<m[i][j]){
                    m[i][j]=q;
                }
            }
        }
    }
    cout<<m[1][n]<<endl;
    return 0;
}