Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int i,j,n,a;
  7.  
  8. cout << "How many elements you want?" << endl;
  9.  
  10. cin >> n;
  11. int A[n+1];
  12. for(int i=0; i<n; i++){
  13. cin >> a;
  14. A[i] = a;
  15. }
  16. for(i=0; i<n+1;i++){
  17. cout << A[i] << " ";
  18. }
  19. int m[n][n], s[n][n], k,l,q;
  20.  
  21. for(i=0; i<n; i++){
  22. for(j=0; j<n; j++){
  23. m[i][j]=0;
  24. cout << m[i][j] << " ";
  25. }
  26. cout << endl;
  27. }
  28.  
  29. for(l=2;l<=n;l++){
  30. for(i=1; i<=(n-l+1); i++){
  31. j=i+l-1;
  32. m[i][j] = 50000;
  33.  
  34. for(k=i; k<=j-1; k++){
  35. q = m[i][k] + m[k+1][j] + A[i-1]*A[k]*A[j];
  36. if(q<m[i][j]){
  37. m[i][j] = q;
  38. }
  39. }
  40. }
  41. }
  42.  
  43. for(i=0; i<n; i++){
  44. for(j=0; j<n; j++){
  45. cout << m[i][j] << " ";
  46. }
  47. cout << endl;
  48. }
  49. //return m && s;
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement