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 <bits/stdc++.h>
using namespace std;


int n;
int p[102], m[102][102]={0};
int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> p[i-1] >> p[i];
	}
	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;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vl p(n+1);
    rep(i,n){
        ll hoge,hogehoge;
        if(i%2==0)cin >> p[i] >> p[i+1];
        else {
            cin >> hoge >>hogehoge;
            if(i==n-1)p[n]=hogehoge;
        }
    }
    vvl dp(n,vl(n,inf));
    rep(i,n)dp[i][i]=0;
    rep(j,n){
        lper(i,j+1,0){
            rep(k,j-i){
                chmin(dp[i][j],dp[i][i+k]+dp[i+k+1][j]+p[i]*p[i+k+1]*p[j+1]);
            }
        }
    }
    cout << dp[0][n-1] <<endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
int dp[105][105];
int q[105];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>q[i-1]>>q[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i==j)	dp[i][j]=0;
			else dp[i][j]=0x3f3f3f3f;
	for(int l=1;l<=n-1;l++){
		for(int i=1;i<=n-l ;i++){
			int j=i+l;
			for(int k=i;k<=j-1;k++){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+q[i-1]*q[k]*q[j]);
			}
		}
	}
	cout<<dp[1][n]<<endl;
}

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>
#define MAX 100
#define INFTY (1 << 21)
using namespace std;

int p[MAX + 1], mat[MAX + 1][MAX + 1];

void matrixChainMultiplication(int n) {
	for (int i = 1; i <= n; i++) {
		mat[i][i] = 0;
	}
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			mat[i][j] = INFTY;
			for (int k = i; k <= j - 1; k++) {
				mat[i][j] = min(mat[i][j], (mat[i][k] + mat[k + 1][j] + (p[i - 1] * p[k] * p[j])));
			}
		}
	}
}

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

C++: #ifdef DEBUG
#include "../utils.cpp"
#endif
#include <bits/stdc++.h>
/*
Problem


Category
DP
 
URL:


考察:



Date: 2020/06/01
*/
 

using namespace std;
using ll = int64_t;
#define int int64_t
#define INF 10e9

 
/* ==== declarations ====== */
// functions
void solve();
void getInput();
 
// global variables
int N;
vector<int> L, R;
vector<vector<int>> dp;

/* ======================== */


void getInput() {
    cin>>N;
    L = vector<int>(N, 0);
    R = vector<int>(N, 0);
    dp = vector<vector<int>>(N, vector<int>(N, 1e9));
    
    for(int i=0; i<N; ++i) {
        cin>>L[i]>>R[i];
    }
}
 

void solve() {
    
    for(int i=0; i<N; ++i) {
        dp[i][i] = 0;
    }
    for(int i=0; i+1<N; ++i) {
        dp[i][i+1] = L[i]*R[i]*R[i+1];
    }

    for(int i=2; i<N; ++i) {
        for(int j=0; i+j < N; ++j) {
            for(int k = 0; k<i; ++k) {
                int p = L[j];
                int q = R[j+k];
                int r = R[j+i];
                dp[j][j+i] = min(dp[j][j+i], p*q*r + dp[j][j+k] + dp[j+k+1][j+i]);

            }
        }
    }
    cout<<dp[0][N-1]<<endl;
}
 
 
signed main(){
    
    getInput();
    solve();
    
    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]<<endl;
  return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(n+1);
    for(int i = 0; i < n; ++i){
        cin >> p[i] >> p[i+1]; 
    }
    vector<vector<int> > dp(n, vector<int>(n));
    for(int d = 1; d < n; ++d){
        for(int i = 0; i < n - d; ++i){
            int j = i + d;
            dp[i][j] = 1 << 30;
            for(int k = i; k < j; ++k){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i] * p[k+1] * p[j+1]);
            }
        }
    }
    cout << dp[0][n-1] << 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;
}