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 <iostream>
using namespace std;
#include <cstdio>
#include <cstdlib>
#include <algorithm>

int n;
int r[100],c[100],dp[100][100]={0},ans=0;

int cal(int i,int j,int k)
{
	return r[i]*c[j]*c[k];
}

int main(void)
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>r[i]>>c[i];
	}
	for (int l=2;l<=n;l++)
	{
		for (int i=1;i+l-1<=n;i++)
		{
			//cout<<"i:"<<i<<" l:"<<l<<endl;
			if (l==2) dp[i][i+l-1]=dp[i+l-1][i]=r[i]*c[i]*c[i+l-1];
			else {
				int m=0x7fffff;
				for (int j=i;j<i+l-1;j++)
				{
					int n=dp[i][j]+dp[j+1][i+l-1]+r[i]*c[j]*c[i+l-1];
					m=m<n?m:n;
				}
				dp[i][i+l-1]=m;
			}
			//cout<<"dp[i][i+l-1]="<<dp[i][i+l-1]<<endl;
		}
	}
	/*for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			cout<<"i:"<<i<<" j:"<<j<<"dp[i][j]:"<<dp[i][j]<<endl;
		}
	}*/
	cout<<dp[1][n]<<endl;
	return 0;
}

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<=n;j++) c[0][j]=0;
	
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;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;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++: const int MAX_SIZE = 101;

int dp[MAX_SIZE][MAX_SIZE];

int solve(int p[], int begin,int end) {
	if (dp[begin][end] != -1)return dp[begin][end];
	if (begin >= end - 1)return 0;
	int res = -1;
	for (int i = begin + 1; i < end; i++) {
		int temp = solve(p, begin, i) + solve(p, i, end) + (p[begin] * p[i] * p[end]);
		if (res != -1) {
			res = min(temp, res);
		}
		else {
			res = temp;
		}
	}
	return dp[begin][end] = res;
}

int main() {
	int N;
	int p[MAX_SIZE + 1];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> p[i] >> p[i + 1];
	}

	for (int i = 0; i < MAX_SIZE; i++) {
		for (int j = 0; j < MAX_SIZE; j++) {
			dp[i][j] = -1;
		}
	}

	cout << solve(p, 0, N) << endl;
	return 0;
}

C++: #include <stdio.h>

int main() {
	int n, i, j, k, l, p[101], m[101][101];
	
	scanf("%d", &n);
	for ( i = 1; i <= n; i++) {
		scanf("%d", &p[i - 1]);
		scanf("%d", &p[i]);
	}
	
	for ( i = 1; i <= n; i++) {
		m[i][i] = 0;
	}
	for ( l = 2; l <= n; l++) {
		for ( i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = ( 1 << 21);
			for ( k = i; k <= j - 1; k++) {
				if ( m[i][j] < m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j]) {
					m[i][j] = m[i][j];
				} else {
					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++: #include <bits/stdc++.h>
using namespace std;

static const int N = 101;

int main(){
    //配列mにはn以下の行列連鎖積の最小回数が格納される
    int n,p[N],m[N][N];
    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++){
            //i,j,kは行列の範囲を表す
            //i<=k<j
            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;
}

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],i,l,j,k;
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> p[i-1] >> p[i];
    }

    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] = (i << 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]);
        }
        }
    }

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

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <climits>
using namespace std;

int mcm(vector<int>& p)
{
    vector<vector<int> > m(p.size() - 1, vector<int>(p.size() - 1));
    for (int i = 0; i < m.size(); i++) {
        m[i][i] = 0;
    }
/*
 * l == number of targets
 * i == left most of targets
 */
    for (int l = 2; l <= m.size(); l++) {
        for (int i = 0; i < m.size() - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = INT_MAX;
            for (int k = i; k < j; k++) {
                m[i][j] =
                    min(m[i][j],
                        m[i][k] + m[k + 1][j] + p[i] * p[k + 1] * p[j + 1]);
            }
        }
    }
    return m[0][m.size() - 1];
}

int main()
{
    int n, x, y;
    cin >> n;
    vector<int> p(n + 1);
    for (int i = i; i < n + 1; i++) {
        cin >> p.at(i - 1) >> p.at(i);
    }
    cout << mcm(p) << endl;
    return 0;
}

C++: #include<iostream>
#include<string>
#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];
  }

  // M[i][j] i=j ならばその掛け算の回数は0回
  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<bits/stdc++.h>
using namespace std;
int f[101][101];
int p[10001];
int n;
int doit(int i,int j){
	 if (f[i][j]!=0x1f1f1f1f)
	    return f[i][j];
	 for (int k=i; k<j; k++)
	 	 f[i][j]=min(f[i][j],doit(i,k)+doit(k+1,j)+p[i-1]*p[k]*p[j]);
	 return f[i][j];
}
    
int main(){
	cin>>n;
	for (int i=1; i<=n; i++)
	    cin>>p[i-1]>>p[i];
	memset(f,0x1f1f1f1f,sizeof(f));
	for (int i=1; i<=n; i++)
	    f[i][i]=0;
	doit(1,n);
    cout<<f[1][n]<<endl;
	return 0;
}