_Maverick_ @ 2023-10-06 08:40:55
#include<iostream>
using namespace std;
int f[21];
int main(){
int n;
cin>>n;
f[0]=1;
f[1]=1;
for(int i=2;i<=n;i++){
f[i]=f[i-1]+f[i-2];
}
cout<<f[n];
return 0;
}
by jqQt0220 @ 2023-10-06 08:42:03
要用高精
by kbzcz @ 2023-10-06 08:42:07
你看看数据范围
by ListentoRain @ 2023-10-06 08:42:25
《对于60%的数据,N<=50》
by _YTY_ @ 2023-10-06 08:42:42
@myh00198100,此题需要高精度
by _Maverick_ @ 2023-10-06 08:44:35
@YTY 哦哦
by cspwhp @ 2023-10-06 09:18:25
《n<=50》
by zhouyk0501 @ 2023-10-08 15:40:58
#include<bits/stdc++.h>
using namespace std;
string dp[10000];
string r(string s){
string s1="";
for(int i=s.size()-1;i>=0;i--){
s1+=s[i];
}return s1;
}
string add(string s,string s1){
int t=0;
while(s.size()<s1.size()) s='0'+s;
while(s1.size()<s.size()) s1='0'+s1;
// cout<<s<<" "<<s1;
for(int i=s.size()-1;i>=0;i--){
int a=s[i]-'0',b=s1[i]-'0';
s[i]=(a+b+t)%10+'0';
// cout<<s2;
t=(a+b+t)/10;
// cout<<s2<<"\n";
}//cout<<s2;
if(t>0){
string s3=to_string(t);
s3=r(s3);
s=r(s);
s+=s3;
s=r(s);
}return s;
}
int main(){
dp[1]="1";
dp[2]="2";
for(int i=3;i<=5010;i++) dp[i]=add(dp[i-1],dp[i-2]);
int n;
cin>>n;
cout<<dp[n];
}