30分,求救!

P1255 数楼梯

pbr806 @ 2024-11-16 14:51:08

#include <bits/stdc++.h>
using namespace std;
int n, b = 1, a[5005][5005];

void floor_num(int n){
    int i;
    for(i = 1;i <= b;i++)
        a[n][i] = a[n-1][i] + a[n-2][i];
    for(i = 1;i <= b;i++){
        if(a[n][i] >= 10){
            a[n][i+1] += a[n][i]/10;
            a[n][i+1]=a[n][i]%10;
            if(a[n][b+1])b++;
        }
    }
}

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

|