题解 | #走方格的方案数#
走方格的方案数
http://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
不能往上或者往右,所以只要到了最底或最右的边上,便只有一条路走到终点了。
#include <iostream> using namespace std; int stepnums(int x, int y) { int num; if(x==0 || y==0) //当处于最右或最下边时,只能有一条路,一直往下或一直往右 num = 1; else //右下角是(0.0),左上角是(x,y)。右移y-,下移x- num = stepnums(x-1, y) + stepnums(x, y-1); return num; } int main() { int n,m; scanf("%d%d",&n,&m); cout << stepnums(n,m); return 0; }