10分求助QWQ

P1255 数楼梯

smendl @ 2023-11-17 16:48:04

#include<bits/stdc++.h>
using namespace std;
long long h[5005];int c[5005],a[5005],b[5005],n;
int jia(long long x,long long y){int cnt=1,ans=1;
    while(x!=0){a[cnt]=x%10;x/=10;cnt++;}while(y!=0){b[ans]=y%10;y/=10;ans++;}
    int maxx;
    if(cnt>ans)maxx=cnt+1;else maxx=ans+1;
    for(int i=1;i<=maxx;i++){c[i]+=a[i]+b[i];c[i+1]+=c[i]/10;c[i]%=10;}
    long long sum=0,chengshu=1;
    for(int i=1;i<=maxx;i++){sum+=chengshu*c[i];chengshu*=10;}
    return sum;}
int main(){
    cin>>n;
    h[1]=1;h[2]=1;
    for(int i=3;i<=n;i++){h[i]=jia(h[i-1],h[i-2]);}
    cout<<h[n];
    return 0;}

by MYiFR @ 2023-11-17 16:51:12

爆 long long 上限了,要写高精度。


by smendl @ 2023-11-17 17:03:13

@MYiFR 谢谢谢谢大神,下次注意


|