1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
此杨辉三角计算公式: a[i][j] = a[i-1][j-1]+a[i-1][j];
与排列组合中:Cij = Ci−1j+Ci−1j−1
具有类似之处,
来一道应用题,
假设要从一个 n 行 m 列的格子的左上角走到右下角,每次只能向右走一步,或者向下走一步,那么有多少种走法?
这道题其实也有动态的身影,
输入格式,(1=<n<=3,3<m<=1000000000)
#include <iostream>
using namespace std;
int main(){
long long n,m;
cin>>n>>m;
if(n == 1){
cout<<1<<endl;
return 0;
}
long long one = 1;
long long two = 0;
long long three = 0;
if(n == 2)
for(int i = 1;i <= m;i ++){
two = two + one;
}
if(n == 3)
for(int i = 1;i <=m ;i ++){
two = two + one;
three = three + two;
}
if(n == 2)
cout<<two<<endl;
if(n == 3)
cout<<three<<endl;
return 0;
}