SHARE
TWEET

ASD Pb 14 veverita

madalinaradu May 26th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<fstream>
  2. using namespace std;
  3. ifstream f("p14-veverita.in");
  4. ofstream g("p14-veverita.out");
  5.  
  6. int a[101][101]; // a[i][j] = va retine cantitatea de ghinde.
  7. int c[101][101]; // c[i][j] = cantitatea maxima (castigul) ce se poate obtine ajungand in pozitia i,j;
  8. // c[i][j] = a[i][j] + max(c[i-1][j],c[i][j-1]);
  9. // adica nr de ghinde din pozitia curenta + (castigul obtinut daca se coboara in jos (c[i-1][j]) sau castigul obtinut daca se muta la dreapta  (c[i][j-1]))
  10. int n,m,i,j;
  11.  
  12. int max(int x, int y) {
  13.     return x>y?x:y;
  14. }
  15.  
  16. int main() {
  17.     // citim datele din fisier
  18.     f>>n>>m;
  19.     for(i=1; i<=n; i++) {
  20.         for(j=1; j<=m; j++) {
  21.             f>>a[i][j];
  22.         }
  23.     }
  24.  
  25.     //calculam matricea castigurilor
  26.     for(i=1; i<=n; i++) {
  27.         for(j=1; j<=m; j++) {
  28.             c[i][j] = a[i][j] + max(c[i-1][j],c[i][j-1]);
  29.         }
  30.     }
  31.     g<<c[n][m];
  32.     f.close();
  33.     g.close();
  34.     return 0;
  35. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top