题目描述
一只蜜蜂在下图所示的数字蜂房上爬动,已知它只能从标号小的蜂房爬到标号大的相邻蜂房,现在问你:蜜蜂从蜂房 m 开始爬到蜂房n(m < n),有多少种爬行路线?
输入格式
输入m,n的值(1
输出格式
爬行有多少种路线。
输入样例
1 14
输出样例
377
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1001], b[1001], c[1001];
int main(){
cin >> n >> m;
a[0] = 1;
a[1] = 1;
memset(b, 0, sizeof(b));
b[0] = 1;
b[1] = 0;
for(int j = n + 1; j <= m; j++){
for(int i = 0; i <= a[0]; i++){
c[i] = a[i];
}
for(int i = 1; i <= a[0]; i++){
a[i] += b[i];
a[i + 1] += a[i] / 10;
a[i] %= 10;
}
while(a[a[0] + 1] > 0){
a[0]++;
}
memset(b, sizeof(b), 0);
for(int i = 0; i <= c[0]; i++){
b[i] = c[i];
}
}
for(int i = a[0]; i >= 1; i--){
cout << a[i];
}
cout << endl;
return 0;
}