4 条题解

  • 7
    @ 2021-8-21 10:29:45

    记忆化搜索

    int dfs(int x, int y) {
        if (dis[x][y])
            return dis[x][y];
    
        dis[x][y] = 1;
    
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
    
            if (nx >= 1 && nx <= n && ny >= 1 && ny <= m &&
                    a[x][y] % a[nx][ny] == 0 &&
                    a[x][y] != a[nx][ny]) {
                dis[x][y] = max(dis[x][y], dfs(nx, ny) + 1);
            }
        }
    
        return dis[x][y];
    }
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n >> m;
    
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                cin >> a[i][j];
    
        int ans = 0;
    
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                ans = max(ans, dfs(i, j));
    
        cout << ans << "\n";
        return 0
    }
    
    • -4
      @ 2024-4-9 20:13:35

      wqeqweasd阿萨德

      • -10
        @ 2022-4-24 16:57:38

        写题解请注意

        鼓励大家写题解,但注意题解格式。

        题解一定要有思路解析或代码注释,能否让别人理解你的思路

        也是你的能力的检验,不要只放无意义的代码给大家复制,那就失去了做题的初心。

        给代码两端加上这个会舒服一些

        ```cpp

        你的代码

        ```

        </span>

        这个点在键盘的左上角tab上面那个键,注意切换输入法

        #include<iostream>
        using namespace std;
        int main()
        {
            int n;
            cin>>n;//这是一个注释
            return 0;
        } 
        

        请注意严禁抄袭题解,写题解不要只放代码,需加上你的思路或代码注释。

        抄袭题解一经发现直接取消成绩。

        题解被删除的可能

        1. 代码不符合格式规范
        2. 没有思路讲解或者没有注释,
        3. 无意义的题解

        大家携手共同维护一个良好的编程环境,如果一经发现,多次作乱。可能会被管理员拉黑,请注意,一旦拉黑即失去登陆资格。

        • -14
          @ 2021-8-20 10:41:58

          请注意:不要在 8 月 21 日 10:30 之前发布本题任何形式的题解,否则你的题解可能会被删除!

          • @ 2022-9-30 20:35:02
            <html><head><link rel="stylesheet" type="text/css" href="/vditor/dist/index.css"/> </head> <body>
            </body></html>
          • @ 2023-8-5 22:58:02

            你前面的时间...... 33DAI 你发布题解的时间......2022.8.21.10.29.45没被删除.....

          • @ 2024-5-6 20:51:19

            @ 那人早被ban了

        • 1

        信息

        ID
        1218
        时间
        1000ms
        内存
        256MiB
        难度
        6
        标签
        递交数
        349
        已通过
        101
        上传者