Advertisement
GerexD

dinamikus-haromszoges

Feb 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ifstream f("haromszog.be");
  8. int n;
  9. f>>n;
  10. int a[n+1][n+1]={0};
  11. for(int i=1;i<=n;i++){
  12. for(int j=1;j<=i;j++){
  13. if(i>=j)
  14. f>>a[i][j];
  15. }}
  16. int b[n+1][n+1]={0};
  17. for(int i=n;i>=1;i--)
  18. {
  19. for(int j=i;j>=1;j--)
  20. {
  21. if(i==n) b[i][j]=a[i][j];
  22. else if( b[i+1][j+1]>=b[i+1][j]) b[i][j]=b[i+1][j+1]+a[i][j];
  23. else b[i][j]=b[i+1][j]+a[i][j];
  24.  
  25. }
  26. }
  27. for(int i=1;i<=n;i++){
  28. for(int j=1;j<=i;j++){
  29. cout<<b[i][j]<<" ";}
  30. cout<<endl;
  31. }
  32. cout<<endl;
  33. cout<<endl;
  34. for(int i=1;i<=n;i++){
  35. for(int j=1;j<=i;j++){
  36. cout<<a[i][j]<<" ";}
  37. cout<<endl;
  38. }
  39. return 0;
  40. }
  41. ++++++++++++
  42. 5
  43. 3
  44. 7 5
  45. 1 8 6
  46. 5 6 4 9
  47. 2 4 7 10 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement