Go: package main

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

var cache [100][100]int

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	tables := []table{}
	for i := 0; i < num; i++ {
		sc.Scan()
		num1, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		num2, _ := strconv.Atoi(sc.Text())
		t := table{num1, num2}
		tables = append(tables, t)
	}

	fmt.Println(minimum(0, len(tables)-1, tables))
}

type table struct {
	v int
	h int
}

func minimum(i int, j int, t []table) int {
	if i == j {
		return 0
	}

	// fmt.Printf("i:%v j:%v\n", i, j)
	if cache[i][j] != 0 {
		return cache[i][j]
	}

	min := math.MaxInt64
	for k := i; k < j; k++ {
		p := t[i].v
		n := t[k].h
		q := t[j].h
		val := minimum(i, k, t) + minimum(k+1, j, t) + p*n*q
		if val < min {
			min = val
		}
	}

	cache[i][j] = min
	return min
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

static const int N = 100;

int main(){
	int n;
	cin >> n;
	int p[N+1];
	int m[N+1][N+1];
	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] = 1e8;
			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;
}

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



int lcs(string x, string y){

  int m = x.length();
  int n = y.length();

  int c[m + 1][n + 1];

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

  for(int i = 1; i <= m; i++){
    for(int j = 1; j <= n; j++){
      if(x[i - 1] == y[j - 1]){
        c[i][j] = c[i - 1][j - 1] + 1;
      }
      else if(c[i - 1][j] > c[i][j - 1]){
        c[i][j] = c[i - 1][j];
      }
      else{
        c[i][j] = c[i][j - 1];
      }
    }

  }

  return c[m][n];
}

int main(){

  int q;

  string x, y;

  cin >> q;

  for(int i = 0; i < q; i++){
    cin >> x;
    cin >> y;
    cout << lcs(x, y) << endl;
  }



  return 0;
}

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

#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)

typedef long long ll;
#define MAX 100+10
const ll inf = 1ll<<50;
ll n,c[MAX],r[MAX];

ll dp(int i,int j){
	if(i == j)return 0;
	ll res = inf;
	forn(k,i,j){
		res = min(res,dp(i,k)+dp(k+1,j)+c[i-1]*r[i-1]*c[k]*r[k]+c[j]*r[j]);
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	forn(i,1,n+1){
		cin >> r[i] >> c[i];
	}
	cout << dp(1,n+1) << "\n";
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;

static const int N = 100;

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