Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int answer = 0;
  4. int h, w;
  5. void find_a_way(int *array[], int count, int pos_x, int pos_y){
  6. count = count + array[pos_x][pos_y];
  7. if((pos_x!=h) || (pos_y!=w)) {
  8. if(pos_x!=::h){
  9. find_a_way(array, count, pos_x+1, pos_y);
  10. };
  11. if(pos_y!=w){
  12. find_a_way(array, count, pos_x, pos_y+1);
  13. };
  14. }
  15. else{
  16. if(count>::answer){
  17. ::answer = count;
  18. };
  19. };
  20. }
  21.  
  22. int main ()
  23. {
  24.  
  25. freopen("/Users/maksimgolish/Desktop/text.txt", "r", stdin);
  26. freopen("/Users/maksimgolish/Desktop/answer.txt", "w", stdout);
  27. cin>>::h>>::w;
  28. int** field;
  29. field = new int*[h];
  30. for(int i=0; i<w; i++){
  31. field[i]=new int[w];
  32. };
  33. for(int i=0; i<h, i++;){
  34. for(int j=0; j<w; j++){
  35. cin>>field[w][h];
  36. }
  37. };
  38.  
  39. find_a_way(field, 0, 0, h);
  40. cout<<::answer;
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement