//JOI2008予選4 #include int check(int x, int y, int count); int table[92][92]; int m, n, i, j, count = 0; int main(void) { int max = 0, total; scanf("%d %d", &m, &n); for(i = 0; i < n; i++) for(j = 0; j < m; j++) scanf("%d", &table[i][j]); printf("n:%d, m:%d\n", n, m); for(i = 0; i < n; i++) for(j = 0; j < m; j++) { total = check(i, j, 0); printf("(%d, %d)を出発点とした割れる最大値 = %d\n", j, i, total); if(total > max) max = total; } printf("%d\n", max); return 0; } int check(int x, int y, int count) { int max = 0, tmp; if(table[x][y]) { count++; table[x][y] = 0; if(x < n-1) if(max < (tmp = check(x+1, y, count))) max = tmp; if(y < m-1) if(max < (tmp = check(x, y+1, count))) max = tmp; if(x > 0) if(max < (tmp = check(x-1, y, count))) max = tmp; if(y > 0) if(max < (tmp = check(x, y-1, count))) max = tmp; table[x][y] = 1; return max; } else return count; }