Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for k := i; k <= j-1; k++ {
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

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