Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int dp[10][10];
- int call(int arr[], int st, int ed)
- {
- if(st == ed) return 0;
- if(dp[st][ed] != -1) return dp[st][ed];
- dp[st][ed] = INT_MAX;
- for(int k=st+1; k<=ed; k++)
- {
- dp[st][ed] = min(call(arr, st, k-1) + call(arr,k,ed) + arr[st-1]*arr[k-1]*arr[ed], dp[st][ed]);
- }
- return dp[st][ed];
- }
- int main()
- {
- int n;
- cin >> n;
- int arr[n];
- for(int i=0; i<n; ++i) cin >> arr[i];
- memset(dp,-1,sizeof(dp));
- cout << call(arr,1,n-1) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement