题解 | #走方格的方案数#
走方格的方案数
https://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
#include <cstring>
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int dp[n + 1][m + 1];
memset(dp, 0, sizeof(dp)); //初始化动态规划
for (int i = 0;i <= n;i++)
{
for (int j = 0;j <= m;j++)
{
if (i == 0 || j == 0)
{
dp[i][j] = 1; //初始状态赋值
}
else
{
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
}
cout << dp[n][m];
}
// 64 位输出请用 printf("%lld")
查看9道真题和解析