Pagini recente » Cod sursa (job #2140953) | Cod sursa (job #167564) | Agm 2018 Runda 2 | corona_day3 | Cod sursa (job #3290930)
#include <iostream>
using namespace std;
#define NMAX 505
int n, prv, l[NMAX], c[NMAX];
long long dp[NMAX][NMAX];
void solve(){
cin>>n>>prv;
for (int i=1; i<=n; ++i){
l[i]=prv;
cin>>prv;
c[i]=prv;
}
for (int st=n-1; st>0; --st){
for (int dr=st+1; dr<=n; ++dr){
dp[st][dr]=0b111111111111111111111111111111111111111111111111111111111111111;
for (int k=st; k<dr; ++k){
long long inm=1LL*l[st]*c[dr]*c[k];
dp[st][dr]=min(dp[st][dr], dp[st][k]+dp[k+1][dr]+inm);
}
}
}
cout<<dp[1][n];
}
int main(){
#ifdef LOCAL
#else
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#endif
freopen("podm.in", "r", stdin);
freopen("podm.out", "w", stdout);
solve();
return 0;
}