擦 犯了个很愚蠢的错误
程序代码:#include<stdio.h>
#define LEN 600
int map[LEN][LEN], n, m;
int lr[LEN * LEN], lc[LEN * LEN];
int tcount, bcount, vlen;
char top[LEN], bottom[LEN], v[LEN][LEN];
int flood(int col, char * mk)
{
int len, br, r, c, h, t, i, count = 0;
char f[LEN][LEN] = {0};
br = n - 1;
f[lr[0] = 0][lc[0] = col] = 1;
if(lr[0] == br) count++;
for(len = 1, i = 0; count < m && i < len; i++)
{
r = lr[i];
c = lc[i];
h = map[r][c];
if((t = r - 1) >= 0 && map[t][c] < h && f[t][c] == 0)
{
f[t][c] = 1;
lr[len] = t;
lc[len++] = c;
}
if((t = c + 1) < m && map[r][t] < h && f[r][t] == 0)
{
f[r][t] = 1;
lr[len] = r;
lc[len++] = t;
if(r == br) count++;
}
if((t = r + 1) < n && map[t][c] < h && f[t][c] == 0)
{
f[t][c] = 1;
lr[len] = t;
lc[len++] = c;
if(t == br) count++;
}
if((t = c - 1) >= 0 && map[r][t] < h && f[r][t] == 0)
{
f[r][t] = 1;
lr[len] = r;
lc[len++] = t;
if(r == br) count++;
}
}
for(i = 0; i < m; i++)
{
if(f[0][i] && !top[i])
{
top[i] = 1;
tcount++;
}
mk[i] = f[br][i];
if(mk[i] && !bottom[i])
{
bottom[i] = 1;
bcount++;
}
}
return count;
}
void analyze(int * out1, int * out2)
{
int count, i, j, k;
int b[LEN] = {0}, bv[LEN] = {0};
for(i = 0; i < m; i++) top[i] = bottom[i] = 0;
for(tcount = bcount = vlen = i = 0; tcount < m;)
{
while(top[i]) i++;
while(i < m - 1 && map[0][i] < map[0][i + 1]) i++;
count = flood(i, v[vlen]);
if(count) vlen++;
if(count == m)
{
*out1 = 1;
*out2 = 1;
return;
}
}
if(bcount < m)
{
*out1 = 0;
*out2 = m - bcount;
return;
}
for(i = 0; i < vlen; i++)
{
for(bv[i] = 1, j = 0; j < m; j++) b[j] += v[i][j];
for(k = 0; k <= i; k++)
{
if(!bv[k]) continue;
for(j = 0; j < m && (!v[k][j] || b[j] > 1); j++);
if(j < m) continue;
for(j = 0; j < m; j++) b[j] -= v[i][j];
bv[k] = 0;
}
}
for(*out1 = 1, *out2 = 0, i = 0; i < vlen; i++) *out2 += bv[i];
}
int main()
{
int i, j;
scanf("%d%d", &n, &m);
for(i = 0; i < n; i++)
for(j = 0; j < m; scanf("%d", &map[i][j++]));
analyze(&i, &j);
printf("%d\n%d\n", i, j);
return 0;
}










