Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,arr[251];
- long long dp[251][251];
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n;
- for(int i=0;i<n;++i)
- cin>>arr[i];
- for(int m=0;m<n;++m)
- {
- for(int i=0,j=m;j<n;++i,++j)
- {
- if(j<i+2)
- dp[i][j]=0;
- else
- {
- dp[i][j]=0;
- for(int k=i+1;k<j;++k)
- {
- long long val=dp[i][k]+dp[k][j]+1LL*arr[i]*arr[j]*arr[k];
- if(dp[i][j]<val)
- dp[i][j]=val;
- }
- }
- }
- }
- cout<<dp[0][n-1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement