P2437 蜜蜂路线(铭记,高精斐波那契数列)

题目背景

题目描述
一只蜜蜂在下图所示的数字蜂房上爬动,已知它只能从标号小的蜂房爬到标号大的相邻蜂房,现在问你:蜜蜂从蜂房 mm 开始爬到蜂房 nn,m

输入格式
输入 m,n 的值

输出格式
爬行有多少种路线

输入输出样例
输入 #1

1 14

输出 #1
377
说明/提示
对于100%的数据,M,N≤1000

#include
#include
#include
#include

using namespace std;
typedef long long ll;

int a[1010][1010];
int m,n,len = 1;

void sf(int x) {
    for(int i = 1; i <= len; i++) {
        a[x][i] = a[x-1][i] + a[x-2][i];
    }
    for(int i = 1; i <= len; i++) {
        if(a[x][i] > 9 ) {
            a[x][i+1] += a[x][i]/10;
            a[x][i]%=10;
        }
    }
    if(a[x][len+1] ) len++;
}

int main() {
    cin >> m >> n;
    a[1][1] = 1,a[2][1] = 2;
    for(int i = 3; i <= n-m; i++) {
        sf(i);
    }
    for(int i = len; i; i--) {
         cout << a[n-m][i];
    }
    return 0;
}


你可能感兴趣的:(程序题目)