volodymyr.zubariev
BAN USERInput:
1
Place1 2 4
3 4 5 6
10 9 8 7
Output:
Place1: 8
What wrong?
p.s. My code looks sad after your modifications :(
It was not my comment, but the code here:
#include <stdio.h>
int a[100][100];
int dist[100][100];
int n, m;
#define max(a,b) ((a)>(b)?(a):(b))
int DepthSearch(int x, int y)
{
if(dist[y][x])
return dist[y][x];
int mx = 0;
if(x > 0 && a[y][x] > a[y][x-1])
mx = max(DepthSearch(x-1, y), mx);
if(x < n-1 && a[y][x] > a[y][x+1])
mx = max(DepthSearch(x+1, y), mx);
if(y > 0 && a[y][x] > a[y-1][x])
mx = max(DepthSearch(x, y-1), mx);
if(y < m-1 && a[y][x] > a[y+1][x])
mx = max(DepthSearch(x, y+1), mx);
dist[y][x] = mx + 1;
return dist[y][x];
}
int solution()
{
int mx = 0;
for(int i = 0; i < m; ++ i)
for(int j = 0; j < n; ++ j)
mx = max(DepthSearch(j, i), mx);
return mx;
}
int main()
{
int T;
scanf("%d", &T);
for(int t = 0; t < T; ++ t)
{
char name[1000];
scanf("%s%d%d", name, &m, &n);
for(int i = 0; i < m; ++ i)
for(int j = 0; j < n; ++ j)
{
scanf("%d", a[i] + j);
dist[i][j] = 0;
}
printf("%s: %d\n", name, solution());
}
return 0;
}
Isn't the answer = Max ( max reach when ? = L, max reach when ? = R )
- volodymyr.zubariev June 05, 2013