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 <iostream>
#include <vector>
#include <functional>


std::vector<std::vector<int>> mats, cost;


int calcMin(int start, int end) {
    if (cost[start][end] != -1) return cost[start][end];

    int min_cost;
    for (int i = start; i < end; i++) {
        int tmp_cost = calcMin(start, i) + calcMin(i + 1, end)
            + mats[start][0] * mats[i][1] * mats[end][1];
        if (i == start) {
            min_cost = tmp_cost;
        }
        if (min_cost > tmp_cost) min_cost = tmp_cost;
    }
    cost[start][end] = min_cost;
    return cost[start][end];
}

int main() {
    int n;
    std::cin >> n;
    
    mats = std::vector<std::vector<int>>(n, std::vector<int>(2));
    cost = std::vector<std::vector<int>> (n, std::vector<int>(n, -1));

    for (int i = 0; i < n; i++) {
        std::cin >> mats[i][0] >> mats[i][1];
    }

    for (int i = 0; i < n; i++) {
        cost[i][i] = 0;
    }

    std::cout << calcMin(0, n - 1) << std::endl;
}

C++: #include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG

struct Matrix {
  int numOfRow;
  int numOfColumn;
};


struct MinMatrix {
  int minMultiply;
  int numOfRow;
  int numOfColumn;
};


MinMatrix getMinScalarMultiply(const Matrix matrices[], int start, int end)
{
  DPRINTF("start %d  end %d\n", start, end);

  assert(start < end);

  if (start >= end)
    return MinMatrix();

  if (start + 1 == end)
  {
    MinMatrix mtx;

    mtx.minMultiply = 0;
    mtx.numOfRow = matrices[start].numOfRow;
    mtx.numOfColumn = matrices[start].numOfColumn;

    return mtx;
  }


  MinMatrix minMtx;
  minMtx.minMultiply = INT_MAX;

  for (int i = start + 1; i < end; i++)
  {
    MinMatrix mtx0 = getMinScalarMultiply(matrices, start, i);
    MinMatrix mtx1 = getMinScalarMultiply(matrices, i, end);

    MinMatrix mtx;

    mtx.minMultiply = mtx0.minMultiply + mtx1.minMultiply + mtx0.numOfRow * mtx0.numOfColumn * mtx1.numOfColumn;
    mtx.numOfRow = mtx0.numOfRow;
    mtx.numOfColumn = mtx1.numOfColumn;

#if DEBUG
    DPRINTF("start %d  end %d  i %d : mtx.minMultiply %d  min.minMultiply %d\n",
        start, end, i, mtx.minMultiply, minMtx.minMultiply);
    DPRINTF("  mtx0.minMultiply %d  mtx1.minMultiply %d\n",
        mtx0.minMultiply, mtx1.minMultiply);
#endif

    if (minMtx.minMultiply > mtx.minMultiply)
      minMtx = mtx;
  }

  DPRINTF("start %d  end %d  multiply %d\n", start, end, minMtx.minMultiply);

  return minMtx;
}


int calcMinScalarMultiply(const Matrix matrices[], int num)
{
  if (num <= 1)
    return 0;

  MinMatrix mtx = getMinScalarMultiply(matrices, 0, num);

  return mtx.minMultiply;
}


int main() {
  int numOfMatrix;
  cin >> numOfMatrix; cin.ignore();

  Matrix  matrices[numOfMatrix];
  for (int i = 0; i < numOfMatrix; i++)
  {
    cin >> matrices[i].numOfRow; cin >> matrices[i].numOfColumn; cin.ignore();
  }

#if DEBUG
  for (int i = 0; i < numOfMatrix; i++)
  {
    DPRINTF("Matrix %d: %d %d\n", i, matrices[i].numOfRow, matrices[i].numOfColumn);
  }
#endif

  cout << calcMinScalarMultiply(matrices, numOfMatrix) << endl;

  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi r(n),c(n);
    rep(i,n){
        cin>>r[i]>>c[i];
    }
    int dp[n+1][n+1];
    MEMSET(dp);
    REP(a,2,n){
        rep(i,n-a+1){
            int j=i+a-1;
            dp[i][j]=inf;
            REP(k,i,j-1){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) {
	int c[N + 1][N + 1];
	int m = X.size();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 1; i <= m; i++)c[i][0] = 0;
	for (int j = 1; j <= m; j++)c[0][j] = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= m; j++) {
			if (X[i] == Y[j]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			}
			else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}
		return maxl;
}

	int main() {
		string s1, s2;
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> s1 >> s2;
			cout << lcs(s1, s2) << 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[i][j] << endl;
			}
		}
	}

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

	return 0;
}

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

static const int N=100;

int main()
{
    int n;
    int 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;
}