Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
int n, t;
std::vector<int> a, f;
std::vector<std::vector<std::vector<long long>>> dp;
void dfs(int d, int s, int l, int r) {
    if (d == n - 1)
        return;
    f[s << 1] = l;
    f[s << 1 | 1] = r;
    dfs(d + 1, s << 1, l, l + r);
    dfs(d + 1, s << 1 | 1, l + r, r);
}
long long solve(int l, int r, int x) {
    if (r - l == 1)
        return 0;
    if (dp[l][r][x] != -1)
        return dp[l][r][x];
    long long ans = 1'000'000'000'000'000'000;
    for (int m = l + 1; m < r; ++m)
        ans = std::min(ans, solve(l, m, x << 1) + solve(m, r, x << 1 | 1) + 1LL * a[m] * (f[x << 1] + f[x << 1 | 1]));
    return dp[l][r][x] = ans;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n;
    a.resize(n);
    f.resize(1 << (n - 1));
    dp.assign(n, std::vector<std::vector<int>>(n));
    for (int l = 0; l < n; ++l)
        for (int r = l + 2; r < n; ++r)
            dp[l][r].assign(1 << (n - r + l), -1);
    for (int i = 0; i < n; ++i)
        std::cin >> a[i];
    dfs(1, 1, 1, 1);
    std::cout << a[0] + a[n - 1] + solve(0, n - 1, 1) << "\n";
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:14: error: no matching function for call to 'std::vector<std::vector<std::vector<long long int> > >::assign(int&, std::vector<std::vector<int> >)'
   33 |     dp.assign(n, std::vector<std::vector<int>>(n));
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<std::vector<long long int> >; _Alloc = std::allocator<std::vector<std::vector<long long int> > >]'
  828 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:828:9: note:   template argument deduction/substitution failed:
a.cc:33:14: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<std::vector<int> >')
   33 |     dp.assign(n, std::vector<std::vector<int>>(n));
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:808:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<std::vector<long long int> >; _Alloc = std::allocator<std::vector<std::vector<long long int> > >; size_type = long unsigned int; value_type = std::vector<std::vector<long long int> >]'
  808 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:808:47: note:   no known conversion for argument 2 from 'std::vector<std::vector<int> >' to 'const std::vector<std::vector<std::vector<long long int> > >::value_type&' {aka 'const std::vector<std::vector<long long int> >&'}
  808 |       assign(size_type __n, const value_type& __val)
      |                             ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_vector.h:855:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<std::vector<long long int> >; _Alloc = std::allocator<std::vector<std::vector<long long int> > >]'
  855 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:855:7: note:   candidate expects 1 argument, 2 provided