Go: package main

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

const N = 100

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var p [N]int
	var m [N + 1][N + 1]int
	for i := 1; i <= n; i++ {
		sc.Scan()
		p[i-1], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		p[i], _ = strconv.Atoi(sc.Text())
	}

	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])
			}
		}
	}

	return fmt.Sprintf("%d", m[1][n])
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
const int MAX_N = 100;

int main() {
    int n; cin >> n;
    int p[MAX_N+1]; rep(i, 1, n+1) cin >> p[i-1] >> p[i];
    
    int dp[MAX_N+1][MAX_N+1];
    rep(i, 1, n+1) dp[i][i] = 0;
    rep(l, 2, n+1){
        rep(i, 1, n-l+2){
            int j = l + i - 1;
            dp[i][j] = (1<<21); // dp[i][j]に巨大な数を入れる
            rep(k, i, j){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }

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

    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;
#define N 100

int main(void){
    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 l = 2;l <= n;++l){
        for(int i = 1;i <= n - l + 1;++i){
            int j = i + l - 1;
            m[i][j] = __INT_MAX__;
            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++: // http://algorithms.blog55.fc2.com/blog-entry-66.html

#include <stdio.h>
#include <string.h>

#define M 100

int N,R[M+1],C[M][M],B[M][M];

void compute(){
	int i=0,j,k,cost;
	memset(C,99,sizeof(C));
	for(;i<N;i++)C[i][i]=0;
	for(j=1;j<N;j++)
		for(i=0;i<N - j; i++ )
			for (k = i; k < i + j; k++ ){
				cost = C[i][k] + C[k+1][i+j] + R[i]*R[k+1]*R[i+j+1];
				if(cost<C[i][i+j])C[i][i+j]=cost,B[i][i+j]=k; 
			}
}

void order( int i, int j ){
	if(i==j)printf("M%d",i);
	else{
		printf("(");
		order( i, B[i][j]-1 ); order(B[i][j], j);
		printf(")");
	}
}

void input(){
	scanf("%d",&N);
	int z,i=0;
	for(;i<N;i++)scanf("%d%d",R+i,&z);
	R[i]=z;
}

void output(){
	printf("%d\n",C[0][N-1]);
	//order(0, N);
	//puts("");
}

main(){
	input();
	compute();
	output();
}

C++: #include <bits/stdc++.h>
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;
};

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

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