leetcode-62.不同路径

1. 题目

2. 解答

dpij表示机器人位于第i,j位置的时候,有多少路径

  1. 如果i = 0,dpij = 1;
  2. 如果j = 0,dpij = 1;
  3. 其他情况dpij = dpi-1j + dpij - 1
c 复制代码
#include <stdio.h>

int solve(int m, int n)
{
    int dp[m][n];

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (i == 0 || j == 0) {
                dp[i][j] = 1;
            } else {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }
    }

    return dp[m -1][n -1];
}

int main()
{
    int m, n;
    scanf("%d %d", &m, &n);

    int result = solve(m, n);

    printf("result:%d\n", result);
}

运行:

c 复制代码
G3-3579:~/data/source/leetcode$ gcc 62differrentpath.c 
G3-3579:~/data/source/leetcode$ ./a.out 
3 7
result:28
G3-3579:~/data/source/leetcode$ ./a.out 
3 2
result:3
G3-3579:~/data/source/leetcode$ ./a.out 
7 3
result:28
G3-3579:~/data/source/leetcode$ ./a.out 
3 3
result:6
相关推荐
贵慜_Derek几秒前
MAI-04|干净数据在工程上意味着什么:MAI 预训练数据治理
人工智能·算法·llm
vibecoding日记18 小时前
双非如何快速入职字节等大厂大模型?真实案例分析:推理优化和投机解码
算法·求职·大模型工程师
yszaygr213820 小时前
Verilog参数化游程编码RLE模块
算法
望易20 小时前
刚设计的大模型架构-双域耦合认知框架
算法·架构
复杂网络1 天前
多个 Claude Code 与多个 Codex 协同工作:设计与实现方案
算法
HjhIron2 天前
面试常客:字符串算法从入门到进阶
算法·面试
吴佳浩2 天前
DeepSeek DSpark:Confidence-Scheduled Speculative Decoding 技术解析
人工智能·算法·deepseek
触底反弹2 天前
🧠 搞懂 Token,才算真正入门大模型——从分词原理到 Embedding 语义实战
javascript·人工智能·算法