rotti321

sumtri

Oct 24th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream f("sumtri.in");
  5. ofstream g("sumtri.out");
  6. int x,d[101][101];
  7. int n;
  8.  
  9. int main()
  10. {
  11. f>>n;
  12. for(int i=1;i<=n;i++)
  13. {
  14. for(int j=1;j<=i;j++){
  15. f>>x;
  16. d[i][j]=max(d[i-1][j-1] + x,d[i-1][j] + x);
  17. ///cout<<d[i][j]<<'\t';
  18. }
  19. ///cout<<'\n';
  20. }
  21. int maxx=d[n][1];
  22. for(int i=1;i<=n;i++){
  23. maxx=max(maxx,d[n][i]);
  24. }
  25. g<<maxx;
  26. return 0;
  27.  
  28. }
Add Comment
Please, Sign In to add comment