Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		fmt.Scan(&a[i+1])
	}

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

	for d := 2; d <= n; d++ {
		for s := 0; s+d <= n; s++ {
			min := 1 << 30
			for j := s+1; j < s+d; j++ {
				val := m[s][j] + m[j][s+d] + a[s]*a[j]*a[s+d]
				if val < min {
					min = val
				}
			}
			m[s][s+d] = min
		}
	}
	fmt.Println(m[0][n])
}

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

using namespace std;

class MatrixMultipluCost{
private:
 vector<unsigned long> p;
 vector< vector<unsigned long> > cost;

public:
 MatrixMultipluCost(unsigned long num)
  : p(num+1, 0), cost(num+1, vector<unsigned long>(num+1, 0)){

  for(unsigned long mat_i = 0; mat_i < num; ++mat_i){
   unsigned long tmp_row = 0; cin >> tmp_row;
   if(mat_i == 0) p[mat_i] = tmp_row;
   unsigned long tmp_col = 0; cin >> tmp_col; p[mat_i+1] = tmp_col;
  }

 };

 unsigned long colculateCost(void){
 unsigned long matrixNum = p.size()-1;

  for(unsigned long distance = 1; distance < matrixNum; ++distance){
   for(unsigned long front_i = 1; front_i+distance <= matrixNum; ++front_i){
    for(unsigned long rear_i = front_i; rear_i < front_i+distance; ++rear_i){
     unsigned long tmp_cost = cost[front_i][rear_i] + cost[rear_i+1][front_i+distance] + p[front_i-1] * p[rear_i] * p[front_i+distance];
     if(cost[front_i][front_i+distance] == 0 || cost[front_i][front_i+distance] > tmp_cost) cost[front_i][front_i+distance] = tmp_cost;
    }
   }
  }

  return cost[1][matrixNum];
 };

 void display(){
  for(unsigned long i = 0, max = p.size(); i < max; ++i)
   cout << p[i] << " ";
  cout << endl;

  for(unsigned long i = 0, max = cost.size(); i < max; ++i){
   for(unsigned long j = 0; j < max; ++j){
    cout << cost[i][j] << " ";
   }
   cout << endl;
  }
 };

};

int main(){
 unsigned long num = 0; cin >> num;

 MatrixMultipluCost MMC(num);
 cout << MMC.colculateCost() << endl;


 return 0;
};

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[111][111],n,L[111],R[111];
int f(int l,int r){
	if(dp[l][r]>-1)return dp[l][r];
	int res=1e9;
	for(int i=l;i<r;i++){
		res=min(res,f(l,i)+f(i+1,r)+L[l+1]*R[i]*R[r]);
	}
	return dp[l][r]=res;
}
main(){
	memset(dp,-1,sizeof(dp));
	r(i,111)dp[i][i]=0;
	cin>>n;
	r(i,n)cin>>L[i]>>R[i];
	cout<<f(0,n-1)<<endl;
}

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

class TMinimumMultiplications
{
	std::vector<std::vector<int> > FTable;
	std::vector<std::pair<int, int> >& FMatrixChain;
	
	int GetMinimum(int Begin, int End);
public:
	TMinimumMultiplications(std::vector<std::pair<int, int> >& MatrixChain);
	
	int Get(int Begin, int End);
};

TMinimumMultiplications::TMinimumMultiplications(std::vector<std::pair<int, int> >& MatrixChain)
: FMatrixChain(MatrixChain), FTable(MatrixChain.size(), std::vector<int>(MatrixChain.size(), -1))
{
}

int TMinimumMultiplications::GetMinimum(int Begin, int End)
{
	int Minimum = INT_MAX;
	for(int i = Begin; i < End; ++i){
		int Total = Get(Begin, i) + Get(i + 1, End) + FMatrixChain[Begin].first * FMatrixChain[i + 1].first * FMatrixChain[End].second;
		if(Minimum > Total) Minimum = Total;
	}
	return Minimum;
}

int TMinimumMultiplications::Get(int Begin, int End)
{
	if(Begin == End) return 0;
	if(FTable[Begin][End] < 0){
		FTable[Begin][End] = GetMinimum(Begin, End);
	}
	return FTable[Begin][End];
}

int main()
{
	int Count;
	std::cin >> Count;
	std::vector<std::pair<int, int> > MatrixChain;
	for(int i = 0; i < Count; ++i){
		int Row, Col;
		std::cin >> Row >> Col;
		MatrixChain.push_back(std::make_pair(Row, Col));
	}
	TMinimumMultiplications Minimum(MatrixChain);
	std::cout << Minimum.Get(0, MatrixChain.size() - 1) << std::endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
static const Aint 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] + 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;

const int INF = 1e9;

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

	vector<vector<int>> dp(n, vector<int>(n, INF));
	for (int i=0;i<n;i++) dp[i][i] = 0;

	for (int w=1;w<n;w++) {
		for (int j=0;j+w<n;j++) {
			for (int k=0;k<w;k++) {
				dp[j][j+w] = min(dp[j][j+w], dp[j][j+k]+dp[j+k+1][j+w]+r[j]*r[j+k+1]*c[j+w]);
			}
		}
	}

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

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

struct Mat{
	  int r,l;
};

int main(){

	  int n; cin >> n;
	  vector<Mat> Mats(n);
	  for(int i=0; i<n; i++)
			cin >> Mats[i].r >> Mats[i].l;

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

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

C++: #include <cstdio>
#include <algorithm>
#define N 100
using namespace std;

int main()
{
  int m[N + 1][N + 1], p[N + 1], n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d%d", &p[i], &p[i + 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] = 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++: //?????????B 
#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; 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>
#include <limits>
using namespace std;

static const int N = 1000;

int main() {
  int n, m[N+1][N+1], p[N+1];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i-1];
    cin >> 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-1; i++) {
      int j = i + l - 1;
      m[i][j] = numeric_limits<int>::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;
}