Go: package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	P := make([]int, n+1)
	for i := 1; i <= n; i++ {
		l := nextInt(sc)
		P[i-1] = l
		m := nextInt(sc)
		P[i] = m
	}

	matrix := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		matrix[i] = make([]int, n+1)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n - l + 1; i++ {
			j := i + l - 1
			matrix[i][j] = (1 << 21)
			for k := i; k <= j-1; k++ {
				matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k+1][j] + P[i-1] * P[k] * P[j])
			}
		}
	}
	fmt.Println(matrix[1][n])
}

C++: #include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct Size {
  int r, c;
};

int main() {
  int n;
  cin >> n;
  vector<Size> M(n);
  for (int i = 0; i < (int)(n); ++i) cin >> M[i].r >> M[i].c;

  const int INF = 1e9;
  vector<vector<int> > dp(n, vector<int>(n, INF));
  for (int i = 0; i < (int)(n); ++i) dp[i][i] = 0;

  for (int l = 2; l <= n; ++l) {
    for (int i = 0; i < (int)(n); ++i) {
      int j = i + l - 1;
      if (j >= n) continue;
      for (int k = i; k + 1 <= j; ++k) {
        chmin(dp[i][j], dp[i][k] + dp[k + 1][j] + M[i].r * M[k].c * M[j].c);
      }
    }
  }

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

  return 0;
}

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

void fnInput(vector<int>& rvnMtrx)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMtrx.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; ++i)
    cin >> rvnMtrx[i] >> rvnMtrx[i + 1];
}

int fnMtrxChainMultpl(vector<vector<int>>& rvvnDetDP, const vector<int>& cnrvnMtrx)
{
  const int nMAXSIZ = cnrvnMtrx.size() - 1;
  for (int i = 1; i <= nMAXSIZ; ++i)  rvvnDetDP[i][i] = 0;

  for (int nDif = 1; nDif <= nMAXSIZ - 1; ++nDif)
    for (int nFrt = 1; nFrt <= nMAXSIZ - nDif; ++nFrt)
    {
      int nBak = nFrt + nDif;
      for (int nx = nFrt; nx <= nBak - 1; ++nx)
        rvvnDetDP[nFrt][nBak] =
          min(rvvnDetDP[nFrt][nBak],
              rvvnDetDP[nFrt][nx] + rvvnDetDP[nx + 1][nBak] 
                                  + cnrvnMtrx[nFrt - 1] * cnrvnMtrx[nx] * cnrvnMtrx[nBak]);
    }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnDetDP; 
  vector<int> vnMtrx;

  fnInput(vnMtrx);
  vvnDetDP.resize(vnMtrx.size(), vector<int>(vnMtrx.size(), INT_MAX));

  fnMtrxChainMultpl(vvnDetDP, vnMtrx);
  cout << vvnDetDP[1][vnMtrx.size() - 1] << endl;
  return 0;
}

C++: #include <bits/stdc++.h> 

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int modpow(int a, int n)
{
    int res = 1;
    while(n > 0)
    {
        if(n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vi p(N+1);
    vvi m(N+1, vi(N+1));
    REP(i, N) cin >> p[i] >> p[i+1];

    REPS(i, N) 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] = INF;
            for(int k = i; k <= j-1; k++)
            {
                chmin(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;

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 = 0; 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 <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	int INFTY = 1000000000;

	int n;
	scanf("%d", &n);

	int p[n + 1];
	for (int i = 0; i < n; i++) {
		scanf("%d %d", p + i, p + i + 1);
	}

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

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			m[i][j] = 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] = INFTY;
			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]);
			}
		}
	}
	cout << m[1][n] << endl;

	return 0;
}

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

#define N 100
int main(){
    int n;
    std::scanf("%d", &n);

    int p[N+1];
    int m[N+1][N+1];

    for(int i = 1; i <= n; ++i){
        std::scanf("%d", &p[i - 1]);
        std::scanf("%d", &p[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] = 0x7FFFFFFF;//large value;                                                                                                                                                                                     
            for(int k = i; k <= j -1; ++k){
                m[i][j] = std::min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    std::printf("%d\n", m[1][n]);

    return 0;
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#define MAX 1000


int lcs(std::string X, std::string Y) {
    int c[MAX][MAX];
    int maxl = 0;
    int m = X.size();
    int n = Y.size();
    for (int i = 1; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int i = 1; i <= n; i++) {
        c[0][i] = 0;
    }
    X = ' ' + X;
    Y = ' ' + Y;
    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] = std::max(c[i-1][j], c[i][j-1]);
            }
            maxl = std::max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main() {
    std::string s1, s2;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        std::cin >> s1 >> s2;
        int a = lcs(s1, s2);
        printf("%d\n", lcs(s1, s2));
    }
    
    return 0;
}