第一个数据点WA了,哪位能帮忙看一下

P1434 [SHOI2002] 滑雪

lucky77__ @ 2020-03-07 01:52:15

include<iostream>

using namespace std;

int r, c;

int a[101][101];

int dx[4] = { 0,0,1,-1 };

int dy[4] = { 1,-1,0,0 };

int flag[101][101];

void dfs(int i,int j)
{
  int nx, ny;
  int temp = 0;
  if (flag[i][j] == 0)
  {
      flag[i][j] += 1;
      for (int k = 0; k < 4; k++)
      {
          nx = i + dx[k];
          ny = j + dy[k];
          if (flag[nx][ny] == 0 && nx <=r && ny <=c&&nx >= 1 && ny >= 1 && a[nx][ny]<a[i][j])
          {
              //如果符合条件
              dfs(nx, ny);
              flag[i][j] -= 1;
          }
          if (flag[nx][ny] != 0 && nx <= r && ny <= c && nx >= 1 && ny >= 1 && a[nx][ny] < a[i][j])
          {
              temp = 1 + flag[nx][ny];
              if(temp>flag[i][j])
              flag[i][j]=temp;
              }
          }
  }
}

int main()
{
  cin >> r >> c;
  for (int i = 1; i <= r; i++)
  {
      for (int j = 1; j <= c; j++)
      {
          cin >> a[i][j];
          flag[i][j] = 0;
      }
  }
  int k = 0;
  for (int i = 1; i <= r; i++)
  {
      for (int j = 1; j <= c; j++)
      {
          dfs(i,j);
      }
  }
  for (int i = 1; i <= r; i++)
  {
      for (int j = 1; j <= c; j++)
          if (flag[i][j] > k)
              k = flag[i][j];
  }
  cout << k << endl;
  return 0;
}

by Smile_Cindy @ 2020-03-07 07:31:19

@lucky77__ 请不要使用Markdown来强调头文件的重要性。


by lucky77__ @ 2020-03-07 12:36:04

@Alpha 不好意思 首次使用


|