Go: package main

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

const N = 100

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

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, N+1)
	m := make([][]int, N+1)
	for i := range m {
		m[i] = make([]int, N+1)
	}
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 1; i <= n; i++ {
		scanner.Scan()
		p[i-1], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		p[i], _ = strconv.Atoi(scanner.Text())
	}
	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
			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])
			}
		}
	}
	fmt.Println(m[1][n])
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[111][111];
signed main(){
  int n;
  cin>>n;
  int r[n],c[n];
  for(int i=0;i<n;i++) cin>>r[i]>>c[i];
  int INF=1LL<<55LL;
  for(int i=0;i<111;i++) fill_n(dp[i],111,INF);
  for(int i=0;i<n;i++) dp[i][i+1]=0;
  for(int i=2;i<=n;i++)
    for(int j=0;j<=n-i;j++)
      for(int k=1;k<i;k++)
	dp[j][j+i]=min(dp[j][j+i],dp[j][j+k]+dp[j+k][j+i]+(r[j]*r[j+k]*c[j+i-1]));
  cout<<dp[0][n]<<endl;
  return 0;
}

C++: #include <stdlib.h>
#include <stdio.h>

int MCM(int n){
int i,j,k,l,m[101][101],p[101],x;

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]=10000000;
        for(k=i;k<=j;k++){
            x=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
            if(m[i][j]>x)m[i][j]=x;
            }
        }
    }
return m[i][j];
}

int main(){

int i,n,m[100];

scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d %d",&m[i],&m[i+1]);
   }
printf("%d\n",MCM(n));
return 0;
}

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;
}