Guest User

Untitled

a guest
Apr 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define Max 130
  4.  
  5. int n;
  6. int Arr[Max];
  7. int table[Max][Max];
  8.  
  9. int main(){
  10. int i, j;
  11. cin >> n;
  12.  
  13. for(i=0; i<n; i++)
  14. scanf("%d",&Arr[i]);
  15.  
  16. for(i=0; i<n; i++)
  17. for(j=0; j<n; j++)
  18. table [i][j] = 0;
  19.  
  20.  
  21. for(i=1; i<=n; i++){
  22. for(j=1; j<=n; j++){
  23. if(i<j)
  24. table[i][j] = max(Arr[i] + table[i-1][j],table[i][j-1] + Arr[j]);
  25. }
  26. }
  27. for(i=0; i<=n; i++){
  28. for(j=0; j<=n; j++){
  29. cout<<table[i][j]<<" ";
  30. }
  31. cout<<endl;
  32. }
  33.  
  34. cout<<table[n-1][n-1]<<endl;
  35. system("pause");
  36. return 0;
  37. }
Add Comment
Please, Sign In to add comment