小明是个调皮的孩子,一天他捉来一只蚂蚁,不小心把蚂蚁的右脚弄伤了,于是蚂蚁只能向上或向右移动。小明把这只蚂蚁放在左下角的方格中,蚂蚁从
左下角的方格中移动到右上角的方格中,每步移动一个方格。蚂蚁始终在方格矩阵内移动,请计算出不同的移动路线的数目。
对于1行1列的方格矩阵,蚂蚁原地移动,移动路线数为1;对于1行2列(或2行1列)的方格矩阵,蚂蚁只需一次向右(或向上)移动,移动路线数也为1……对于一个2行3列的方格矩阵,如下图所示:
-------------------
|(2,1)|(2,2)|(2,3)|
-------------------
|(1,1)|(1,2)|(1,3)|
-------------------
蚂蚁共有3种移动路线:
路线1:(1,1) → (1,2) → (1,3) → (2,3)
路线2:(1,1) → (1,2) → (2,2) → (2,3)
路线3:(1,1) → (2,1) → (2,2) → (2,3)
2 3
3
#if 1
#include<bits/stdc++.h>
using namespace std;
int m , n ;
int ok(int i ,int j)
{
return ( i == m || j == n ) ;
}
int fun(int x, int y)
{
if(ok(x,y))
return 1;
else
return fun(x+1,y) +fun (x,y+1) ;
}
int main()
{
int a[25][25] ;
cin >> m >> n ;
cout << fun(1,1) <<endl;
}
#endif
393



被折叠的 条评论
为什么被折叠?



