xuyutong1234 @ 2024-09-01 22:13:51
#include<bits/stdc++.h>
using namespace std;
long long a[5005];
int main(){
int n;cin>>n;
a[1]=1;a[2]=2;
for(int i=3;i<=n;i++){
a[i]=a[i-2]+a[i-1];
}
cout<<a[n];
return 0;
}
by hanxiaofensheng @ 2024-09-01 22:27:01
#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;
}
你用这个代码试试
by hyl_____ @ 2024-09-01 22:31:54
@xuyutong1234 要用高精