Advertisement
splash365

Untitled

Oct 7th, 2020 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int dp[10][10];
  5.  
  6. int call(int arr[], int st, int ed)
  7. {
  8.     if(st == ed) return 0;
  9.     if(dp[st][ed] != -1) return dp[st][ed];
  10.     dp[st][ed] = INT_MAX;
  11.     for(int k=st+1; k<=ed; k++)
  12.     {
  13.         dp[st][ed] = min(call(arr, st, k-1) + call(arr,k,ed) + arr[st-1]*arr[k-1]*arr[ed], dp[st][ed]);
  14.     }
  15.     return dp[st][ed];
  16. }
  17.  
  18. int main()
  19. {
  20.     int n;
  21.     cin >> n;
  22.     int arr[n];
  23.     for(int i=0; i<n; ++i) cin >> arr[i];
  24.     memset(dp,-1,sizeof(dp));
  25.     cout << call(arr,1,n-1) << endl;
  26. }
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement