Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int m , n , i , j;
- bool a[200] , hodmax[200];;
- int map[100][100] , coordsmax[100][100] , coordposmin[100][100];
- bool check(int x , int y) {
- if ((x < m and y < n) and (x >= 0 and y >= 0))
- return true;
- else
- return false;
- }
- void run(int x , int y , bool hod[200] , int pos , int s) {
- int i;
- if (coordsmax[x][y] < s or (coordsmax[x][y] == s and coordposmin[x][y] > pos )) {
- coordposmin[x][y] = pos;
- coordsmax[x][y] = s;
- if (not (x == 0 and y == n - 1)) {
- if (check(x - 1 , y)) {
- hod[pos] = false;
- run(x - 1 , y , hod , pos + 1 , s + map[x - 1][y]);
- }
- if (check(x , y + 1)) {
- hod[pos] = true;
- run(x , y + 1, hod , pos + 1 , s + map[x][y + 1]);
- }
- }
- else
- for (i = 0 ; i < coordposmin[x][y] ; i++)
- hodmax[i] = hod[i];
- }
- }
- int main() {
- scanf("%i %i",&m,&n);
- for (i = 0 ; i < m ; i++)
- for (j = 0 ; j < n ; j++) {
- scanf("%i",&map[i][j]);
- coordposmin[i][j] = 999;
- }
- run(m - 1 , 0 , a , 0 , map[m - 1][0]);
- for (i = 0 ; i < coordposmin[0][n - 1] ; i++)
- if (hodmax[i] == false)
- printf("F");
- else
- printf("R");
- return 0;
- }
Add Comment
Please, Sign In to add comment