Advertisement
Sunt_tare

Untitled

Nov 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("taxe.in");
  6. ofstream fout("taxe.out");
  7.  
  8. const int CMAX = 205;
  9. int desert[CMAX][CMAX] , desert2[CMAX][CMAX] , n , m , i  , j , minim = 90000;
  10.  
  11. void citire()
  12. {
  13.     fin >> n >> m;
  14.     for(i=1;i<=n;i++)
  15.         for(j=1;j<=m;j++){
  16.             fin >> desert[i][j];
  17.             desert2[i][j] = desert[i][j];
  18.         }
  19. }
  20.  
  21. void afisare()
  22. {
  23.     for(i=1;i<=n;i++)
  24.     {
  25.         for(j=1;j<=m;j++)
  26.         {
  27.             cout << desert2[i][j] << " ";
  28.         }
  29.         cout << '\n';
  30.     }
  31.     cout << '\n';
  32. }
  33.  
  34. bool OK(int coi,int coj)
  35. {
  36.     if(coi<=0||coj<=0||coi>n||coj>m)
  37.         return false;
  38.     return true;
  39. }
  40.  
  41. int main()
  42. {
  43.     citire();
  44.     for(j=m-1;j>=1;j--)
  45.     {
  46.         for(i=1;i<=n;i++)
  47.         {
  48.             if(i==1)
  49.             {
  50.                 if(desert2[i][j+1]>desert2[i+1][j+1]) desert2[i][j]+= desert2[i+1][j+1];
  51.                 else desert2[i][j]+= desert2[i][j+1];
  52.             }
  53.             else if(i==n)
  54.             {
  55.                 if(desert2[i][j+1]>desert2[i-1][j+1]) desert2[i][j]+= desert2[i-1][j+1];
  56.                 else desert2[i][j]+= desert2[i][j+1];
  57.             }
  58.             else{
  59.                 if(desert2[i-1][j+1]>desert2[i+1][j+1])
  60.                 {
  61.                     if(desert2[i+1][j+1]<desert2[i][j+1])
  62.                     {
  63.                         desert2[i][j]+= desert2[i+1][j+1];
  64.                     }
  65.                     else
  66.                     {
  67.                         desert2[i][j]+= desert2[i][j+1];
  68.                     }
  69.                 }
  70.                 else
  71.                 {
  72.                     if(desert2[i-1][j+1]>desert2[i][j+1])
  73.                     {
  74.                         desert2[i][j]+= desert2[i][j+1];
  75.                     }
  76.                     else
  77.                     {
  78.                         desert2[i][j]+= desert2[i-1][j+1];
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.     }
  84.     for(i=1;i<=n;i++)
  85.         if(minim>desert2[i][1]) minim = desert2[i][1];
  86.     fout << minim;
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement