题解 | #走方格的方案数#
走方格的方案数
https://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
#include<stdio.h>
int fun(m, n)
{
int sum = 0;
if (m == 1)
{
sum += (1 + n);
}
if (n == 1&&!(m==1))
{
sum += (1 + m);
}
if (m > 1 && n > 1)
{
sum += fun(m - 1, n) + fun(m, n - 1);
}
return sum;
}
int main(void)
{
int n;
int m;
scanf("%d%d", &n, &m);
int sum = fun(m, n);
printf("%d", sum);
return 0;
}
int fun(m, n)
{
int sum = 0;
if (m == 1)
{
sum += (1 + n);
}
if (n == 1&&!(m==1))
{
sum += (1 + m);
}
if (m > 1 && n > 1)
{
sum += fun(m - 1, n) + fun(m, n - 1);
}
return sum;
}
int main(void)
{
int n;
int m;
scanf("%d%d", &n, &m);
int sum = fun(m, n);
printf("%d", sum);
return 0;
}