SHARE
TWEET

fmm cighir

a guest Nov 12th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream f("taxe.in");
  6. ofstream g("taxe.out");
  7.  
  8. int A[205][205],B[205][205],n,m;
  9.  
  10. void citire()
  11. {
  12.     f>>n>>m;
  13.     for(int i=1;i<=n;i++)
  14.         for(int j=1;j<=m;j++)
  15.             f>>A[i][j];
  16. }
  17.  
  18. void taxe()
  19. {
  20.     for(int j=n;j>=1;j--)
  21.         B[j][m] = A[j][m];
  22.  
  23.     for(int j=m-1;j>=1;j--)
  24.     {
  25.         B[1][j]=min(B[1][j+1],B[2][j+1])+A[1][j];
  26.         B[n][j]=min(B[n][j+1],B[n-1][j+1])+A[n][j];
  27.         for(int i=2;i<n;i++)
  28.             B[i][j]=A[i][j]+min(min(B[i][j+1],B[i-1][j+1]),B[i+1][j+1]);
  29.     }
  30.  
  31.  
  32. }
  33.  
  34. int minim()
  35. {
  36.     int mini=B[1][1];
  37.     for(int j=1;j<=n;j++)
  38.         if(B[j][1]<mini)
  39.         mini=B[j][1];
  40.     return mini;
  41. }
  42.  
  43. int main()
  44. {
  45.     citire();
  46.     taxe();
  47.     g<<minim();
  48.  
  49.     return 0;
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top