Vladislav_Bezruk

Some task

Nov 16th, 2020 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int m , n , i , j;
  4. bool a[200] , hodmax[200];;
  5. int map[100][100] , coordsmax[100][100] , coordposmin[100][100];
  6.  
  7. bool check(int x , int y) {
  8.    
  9.     if ((x < m and y < n) and (x >= 0 and y >= 0))
  10.     return true;
  11.     else
  12.     return false;
  13.    
  14. }
  15.  
  16. void run(int x , int y , bool hod[200] , int pos , int s) {
  17.     int i;
  18.    
  19.     if (coordsmax[x][y] < s or (coordsmax[x][y] == s and coordposmin[x][y] > pos )) {
  20.         coordposmin[x][y] = pos;
  21.         coordsmax[x][y] = s;
  22.         if (not (x == 0 and y == n - 1)) {   
  23.             if (check(x - 1 , y)) {
  24.                 hod[pos] = false;  
  25.                 run(x - 1 , y , hod , pos + 1 , s + map[x - 1][y]);
  26.             }
  27.             if (check(x , y + 1)) {
  28.                 hod[pos] = true;   
  29.                 run(x , y + 1, hod , pos + 1 , s + map[x][y + 1]); 
  30.             }              
  31.         }
  32.         else
  33.         for (i = 0 ; i < coordposmin[x][y] ; i++)
  34.         hodmax[i] = hod[i];
  35.     }                  
  36. }
  37.  
  38. int main() {
  39.    
  40.     scanf("%i %i",&m,&n);
  41.    
  42.     for (i = 0 ; i < m ; i++)
  43.     for (j = 0 ; j < n ; j++) {
  44.         scanf("%i",&map[i][j]);    
  45.         coordposmin[i][j] = 999;   
  46.     }
  47.    
  48.     run(m - 1 , 0 , a , 0 , map[m - 1][0]);
  49.      
  50.     for (i = 0 ; i < coordposmin[0][n - 1] ; i++)
  51.     if (hodmax[i] == false)
  52.     printf("F");
  53.     else
  54.     printf("R");   
  55.  
  56.     return 0;
  57. }
Add Comment
Please, Sign In to add comment