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++: // ALDS1_10_B Matrix Chain Multiplication
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define INF 900000000
bool debug = false;
std::vector<std::vector<int>> dp;

void MatrixChainMultiplication(std::vector<std::pair<int,int>> sequence) {
    dp.resize(sequence.size());
    for (int i=0; i<dp.size(); i++) dp.at(i).resize(sequence.size());

    /*
    example:
        aN is a matrix. 
        ... a3 (a4 a5 a6)*(a7 a8) a9 ...
        i = 5, j = 4, k = 3
    */

    /* i = length of set */
    for (int i=2; i<dp.size(); i++) {
        /* j = front point */
        for (int j=1; j<=dp.at(i).size()-i; j++) {
            /* initialization of dp.at(i).at(j) */
            dp.at(i).at(j) = INF;
            /* k = dividing point */
            for (int k=1; k<i; k++) {
                if (i == 2) {
                    dp.at(i).at(j) = sequence.at(j).first*sequence.at(j).second*sequence.at(j+1).second;
                } else {
                    dp.at(i).at(j) = std::min(dp.at(i).at(j),
                                              dp.at(k).at(j)+dp.at(i-k).at(j+k)+sequence.at(j).first*sequence.at(j+k-1).second*sequence.at(i+j-1).second);
                    
                }
            }
            if (debug) {
                std::cout << "dp.at(" << i << ").at(" << j << ") = " << dp.at(i).at(j) << ":";
                for (int n=j; n<i+j; n++) std::cout << " " << n;
                std::cout << "\n";
            }
        }
    }
    std::cout << dp.back().at(1) << "\n";
}

int main() {
    int total; std::cin >> total;
    std::vector<std::pair<int,int>> sequence;
    sequence.resize(total+1);
    for (int i=1; i<sequence.size(); i++) {
        std::cin >> sequence.at(i).first >> sequence.at(i).second;
    }
    MatrixChainMultiplication(sequence);
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef float fl;
typedef long long ll;

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 <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

int main(){
	int n;
	cin >> n;
	int i, t, A[n+1];
	cin >> A[0] >> A[1];
	for(i = 2; i <= n; i++){
		cin >> t >> A[i];
	}

	//dp[l][r] -> min(A[l]*...*A[r])
	int dp[n][n+1]{}, dplr, l, r;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < n-i; j++){
			l = j;
			r = j+i;
			dplr = INT_MAX;
			for(int k = l; k < r; k++){
				dplr = min(dplr, dp[l][k] + dp[k+1][r] + A[l]*A[k+1]*A[r+1]);
			}
			dp[l][r] = dplr;
			//printf("[%d, %d]=%d ", l, r, dplr);
		}
		//printf("\n");
	}

	printf("%d\n", dp[0][n-1]);
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int a[44],n;
  a[0]=a[1]=1;
  cin>>n;
  for(int i=2;i<=n;i++)a[i]=a[i-1]+a[i-2];
  cout<<a[n]<<endl; 
}

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

struct Mat{
	  int r,c;
};

int main(){

	  int n; cin >> n;
	  vector<Mat> Mats(n);
	  for(int i=0; i<n; i++)
			cin >> Mats[i].r >> Mats[i].c;

	  int dp[n][n] = {};
	  for(int i=0; i<n; i++)
			for(int j=0; j<n; j++)
				  if(i==j) dp[i][j] = 0;
				  else dp[i][j] = INT_MAX;

	  for(int w=1; w<n; w++){
			for(int i=0; i+w<n; i++){
				  int j = i+w;
				  for(int k=i; k<j; k++){
						int num_prod = Mats[i].r * Mats[k+1].r * Mats[i+w].c;
						dp[i][i+w] = min(dp[i][i+w], dp[i][k] + dp[k+1][i+w] + num_prod);
				  }
			}
	  }
/*
	  for(int i=0; i<n; i++){
			for(int j=0; j<n; j++)
				  cout << dp[i][j] << " ";
			cout << endl;
	  }
*/	  
	  cout << dp[0][n-1] << endl;
	  
			
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
void MatrixChain(int *p, int n, int **m, int **s)
{
	for (int i = 1;i <=n;i++)
		m[i][i] = 0;
	for (int r = 2;r <= n;r++)
	{
		for (int i = 1;i <= n - r + 1;i++)
		{
			int j = i + r - 1;
			m[i][j] = m[i + 1][j] + (p[i - 1] * p[i] * p[j]);
			s[i][j] = i;
			for (int k = i + 1;k < j;k++)
			{
				int t = m[i][k] + m[k + 1][j] + (p[i - 1] * p[k] * p[j]);
				if (t < m[i][j])
				{
					m[i][j] = t;
					s[i][j] = k;
				}
			}
		}
	}
}

void print(int i, int j, int **s)
{
	if (i == j)
		cout << "A" << i;
	else
	{
		cout << "(";
		print(i, s[i][j], s);
		print(s[i][j] + 1, j, s);
		cout << ")";
	}
}
int main()
{
	int n;
	cin >> n;
	int *tempP = new int[2 * n]; 
	int *p = new int[n + 1];   
	int **m = new int *[n + 1]; 
	int **s = new int *[n + 1]; 
	for (int i = 1; i <= n; i++)
	{
		m[i] = new int[n + 1];
		s[i] = new int[n + 1];
	}

	for (int i = 0; i < 2 * n; i++)
	{
		cin >> tempP[i];
	}

	for (int i = 0; i <= n; i++)
	{
		p[i] = (i == 0 ? tempP[0] : tempP[i * 2 - 1]);
	}
	MatrixChain(p, n, m, s);
	cout << m[1][n] << endl; 
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int mcm(int p[], int n) {
	int m[n+1][n+1];
	memset(m, 0, sizeof(m));

	for (int s = 0; s < n; s++) {
		for (int i = 1, j = s + 2; j <= n; i++, j++) {
			m[i][j] = 1 << 30;
			for (int k = i; k <= j; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
			}
		}
	}
	return m[1][n];
}

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

C++: #include <cstdio>
#include <climits>

int convert(int p, int size, int n){
    for(int i=1;i<size;i++)p+=n--;
    return p;
}

int multipulication(int *r, int *c, int *count, int p, int size, int n){
    if(size==1)return 0;
    int id = convert(p,size,n);
    if(count[id])return count[id];
    int mlt = INT_MAX;
    int i, tmp;
    for(i=1;i<size;i++){
        tmp = r[p]*r[p+i]*c[p+size-1] + multipulication(r,c,count,p,i,n) + multipulication(r,c,count,p+i,size-i,n);
        if(tmp<mlt)mlt=tmp;
    }
    count[id] = mlt;
    return mlt;
}

int main(){
    int i, n;
    scanf("%d",&n);
    int r[n];
    int c[n];
    int count[n*(n+1)/2];
    for(i=0;i<n*(n+1)/2;i++)count[i]=0;
    for(i=0;i<n;i++)scanf("%d %d",r+i,c+i);
    printf("%d\n",multipulication(r,c,count,0,n,n));
    return 0;
}

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

#define MAX_N 10000
#define INF 10000000LL

long long n, j, x[MAX_N][MAX_N], p[MAX_N + 2];

int matrix() {
	for (int i = 0; i < n; i++) { x[i][i] = 0; }
	for (int h = 2; h <= n; h++) {
		for (int i = 1; i <= n - h + 1; i++) {
			j = i + h - 1;
			x[i][j] = INF;
			for (int k = i; k < j; k++) {
				x[i][j] = min(x[i][j], x[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	return x[1][n];
}

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