60分求救!

P1255 数楼梯

Yews @ 2024-09-06 20:03:23

#include <bits/stdc++.h>
using namespace std;
int n;
long long f[5002];
int main(){
    cin >> n;
    f[1] = 1;
    f[2] = 2;
    for(int i = 3;i <= n;i++){
        f[i] = f[i - 1] + f[i - 2];
    }
    cout << f[n];
    return 0;
}

by hanxiaofensheng @ 2024-09-06 20:11:41

#include<bits/stdc++.h>
using namespace std;
int n,len=1,f[5003][5003];
void hp(int k) {    
    int i;
    for(i=1;i<=len;i++) f[k][i]=f[k-1][i]+f[k-2][i]; 
    for(i=1;i<=len;i++)             
        if(f[k][i]>=10){
            f[k][i+1]+=f[k][i]/10;
            f[k][i]=f[k][i]%10;
            if(f[k][len+1])len++;
    }
}
int main(){
    int i;
    scanf("%d",&n);
    f[1][1]=1; f[2][1]=2;          
    for(i=3;i<=n;i++) hp(i);                         
    for(i=len;i>=1;i--)printf("%d",f[n][i]);
    return 0;
}

这道题要用高薪度做才能ac, 求关注


by lined_array @ 2024-09-07 13:38:14

@hanxiaofensheng 谢谢!!!


by __lihaoyu68__ @ 2024-09-09 08:25:32

@hanxiaofensheng
这不是第一篇题解吗


|