/home/toolbox/public_html/solutions/102/10285/c.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #include <stdint.h>
9 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (TRUE)
15
16 /* fprintf(stderr, "functionName: message", varslist); */
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2023-11-14
21 * Purpose: fun
22 * Problem: 10285
23 */
24
25 /*
26 * This template reads data a specified number of times.
27 */
28
29 #define MAX_SIZE 102
30 #define MAX_STRING 1024
31 #define MAX_HEIGHT 200
32
33 int numberOfTimes;
34 char name[MAX_STRING];
35 int ary[MAX_SIZE][MAX_SIZE];
36 int ans[MAX_SIZE][MAX_SIZE];
37 int r;
38 int c;
39
40 void init()
41 {
42 /* FUNCTION init */
43 scanf("%d ", &numberOfTimes);
44 } /* FUNCTION init */
45
46 void dump()
47 {
48 /* FUNCTION dump */
49 } /* FUNCTION dump */
50
51 void getInput()
52 {
53 /* FUNCTION getInput */
54 int i;
55 int j;
56
57 scanf("%s %d %d ", name, &r, &c);
58 for (i=0; i<r; i++)
59 {
60 /* each row */
61 for (j=0; j<c; j++)
62 {
63 /* fpor each column */
64 scanf(" %d ", &ary[i][j]);
65 ans[i][j]=0;
66 } /* fpor each column */
67 } /* each row */
68 } /* FUNCTION getInput */
69
70 int check(int row, int col, int high)
71 {
72 /* FUNCTION check */
73 int toReturn = 0;
74 int tmp;
75
76 DEBUG printf("check %d/%d %d/%d (high %d) (ary %d) (ans %d)\n", row, r, col, c, high, ary[row][col], ans[row][col]);
77 if (high <= ary[row][col])
78 {
79 /* invalid move - return 0 */
80 toReturn = 0;
81 } /* invalid move - return 0 */
82 else if (0 < ans[row][col])
83 {
84 /* found an answer */
85 toReturn = ans[row][col];
86 } /* found an answer */
87 else
88 {
89 /* check the four arouond */
90 if (0 < row)
91 {
92 /* check row above */
93 tmp = 1 + check(row - 1, col, ary[row][col]);
94 toReturn = (tmp > toReturn) ? tmp : toReturn; /* get biggest number */
95 } /* check col above */
96 if (0 < col)
97 {
98 /* check col to left */
99 tmp = 1 + check(row, col - 1, ary[row][col]);
100 toReturn = (tmp > toReturn) ? tmp : toReturn; /* get biggest number */
101 } /* check row to left */
102 if (r > row)
103 {
104 /* check row below */
105 tmp = 1 + check(row + 1, col, ary[row][col]);
106 toReturn = (tmp > toReturn) ? tmp : toReturn; /* get biggest number */
107 } /* check row below */
108 if (c > col)
109 {
110 /* check col to right */
111 tmp = 1 + check(row, col + 1, ary[row][col]);
112 toReturn = (tmp > toReturn) ? tmp : toReturn; /* get biggest number */
113 } /* check row to right */
114 } /* check the four arouond */
115 if (toReturn > ans[row][col])
116 {
117 /* found a bigger answeer */
118 ans[row][col] = toReturn;
119 printf("Setting ans[%d][%d] to %d\n", row, col, toReturn);
120 } /* found a bigger answeer */
121 return toReturn;
122 } /* FUNCTION check */
123
124 void process()
125 {
126 /* FUNCTION process */
127 /* i,r j,c */
128 int i;
129 int j;
130 int tmp;
131 int maxx = 0;
132
133 DEBUG printf("process %s %d %d\n", name, r, c);
134 for (i=0; i<r; i++)
135 {
136 /* each row */
137 for (j=0; j<c; j++)
138 {
139 /* for each column */
140 if (0 == ans[i][j])
141 {
142 /* uncalculated value found */
143 DEBUG printf("Calling check: %d %d\n", i, j);
144 tmp = check(i, j, MAX_HEIGHT);
145 if (tmp > maxx)
146 {
147 maxx = tmp;
148 }
149 } /* uncalculated value found */
150 } /* for each column */
151 } /* each row */
152 printf("%s: %d\n", name, maxx);
153 } /* FUNCTION process */
154
155 int main()
156 {
157 /* main */
158 int i;
159
160 init();
161 for (i=0; i<numberOfTimes; i++)
162 {
163 /* while */
164 getInput();
165 process();
166 } /* while */
167
168 return EXIT_SUCCESS;
169 } /* main */
170
171