这个是poj1088滑雪的源代码,请问这个有啥错误呀?为什么每次都是Runtime Error??谢谢

CharlesYJ 2012-08-16 10:12:12
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int row,col;
int height[100][100];
//存放每个点的结果
int length[100][100];


int dp(int i,int j)
{
int max = 0;
int temp;
if(length[i][j] > 0 )
return length[i][j];

if(j-1 >= 0) {
if( height[i][j] > height[i][j-1] ) {
temp = dp(i,j-1);
if ( max < temp)
max = temp;

}
}

if(i-1 >=0) {
if(height[i][j] > height[i-1][j] ) {
temp = dp(i-1,j);
if(max < temp)
max = temp;

}

}

if(j+1 < col) {

if (height[i][j] > height[j][j+1] ) {
temp = dp(i,j+1);
if(max < temp)
max = temp;
}
}

if(i+1 < row) {

if(height[i][j] > height[i+1][j] ) {
temp = dp(i+1,j);
if (max < temp)
max = temp;
}

}

length[i][j] = max + 1;
return length[i][j];

}




int main(void)
{
int i,j;
int max = -1;
scanf("%d %d",&row,&col);

memset(length,0,sizeof(length));

for( i = 0;i<row;i++) {
for (j =0;j<col;j++) {
scanf("%d",&height[i][j]);
//printf("%d ",height[i][j]);
}
}

for( i = 0; i < row;i++) {
for(j=0; j < col; j++) {
max = dp(i,j);
}
}

max = length[0][0];

for ( i = 0;i<row;i++) {
for(j=0;j<col;j++) {
if(length[i][j] > max)
max = length[i][j];
}
}

printf("%d\n",max);

//system("pause");
return 0;

}




...全文
93 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
logiciel 2012-08-17
  • 打赏
  • 举报
回复
以下这行有个下标错了:
if (height[i][j] > height[j][j+1] ) {
改为:
if (height[i][j] > height[i][j+1] ) {
logiciel 2012-08-17
  • 打赏
  • 举报
回复
以下这行有个下标错了:
if (height[i][j] > height[j][j+1] ) {
改为:
if (height[i][j] > height[i][j+1] ) {
CharlesYJ 2012-08-16
  • 打赏
  • 举报
回复
这是题目链接;http://poj.org/problem?id=1088

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧