yzh___nb @ 2023-10-09 09:47:31
#include<bits/stdc++.h>
using namespace std;
long long f[5001];
int main()
{
int n;
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 fztt_r9 @ 2023-10-09 09:50:14
#include<iostream>
using namespace std;
int f[5010][2010]; //存储每一项都是高精度数的递推序列
int main()
{
int n;
cin>>n;
f[0][0] = 1,f[0][1] = 0; //第0项,高精度是0(过输入0的测试点)
f[1][0] = f[1][1] = 1; //第1项,高精度数1
f[2][0] = 1,f[2][1] = 2; //第2项,高精度数2
for(int i=3;i<=n;i++){
int x = 0;
for(int j=1;j<=f[i-1][0] || j<=f[i-2][0];j++){
f[i][0]++;
f[i][j] = f[i-1][j] + f[i-2][j] + x;
if(f[i][j]>=10) f[i][j] -= 10,x = 1;
else x = 0;
}
if(x) f[i][++f[i][0]] = x;
}
for(int i=f[n][0];i>=1;i--) cout<<f[n][i];
return 0;
}
by MYiFR @ 2023-10-09 09:51:58
#include<bits/stdc++.h>
using namespace std;
const int N=5007;
char s[N];
struct node{
int len,num[N];
void init(){
memset(num,0,sizeof(num));
len=1;
}
void read(){
cin>>s+1;
len=strlen(s+1);
for(int i=1;i<=len;i++){
num[len-i+1]=s[i]-48;
}
}
void write(){
for(int i=len;i>=1;i--){
printf("%d",num[i]);
}
printf("\n");
}
}s1,s2,ans;
node operator + (node a,node b){
node c;
c.init();
c.len=max(a.len,b.len);
for(int i=1;i<=c.len;i++){
c.num[i]+=a.num[i]+b.num[i];
if(c.num[i]>=10){
c.num[i]-=10;
c.num[i+1]++;
}
}
if(c.num[c.len+1]!=0) c.len++;
return c;
}
int main(){
s1.read();
s2.read();
ans=s1+s2;
ans.write();
return 0;
}
by MYiFR @ 2023-10-09 09:52:51
板子,自己把 f 套一下
by Special_Tony @ 2023-10-09 10:46:44
@yzh___nb py是摆设吗题解是摆设吗
by zqhbxsgs @ 2023-10-27 22:12:34
#include<bits/stdc++.h>
using namespace std;
int n,x[5010][1500],y[5010];
void f(int s){
for(int i = 1;i <= y[s - 1];i ++){
x[s][i] += x[s - 1][i] + x[s - 2][i];
x[s][i + 1] += x[s][i] / 10;
x[s][i] %= 10;
}
y[s] = max(y[s - 1],y[s - 2]) + 1;
for(;!x[s][y[s]];){
y[s] --;
}
}
int main() {
cin >> n;
x[1][1] = 1,x[2][1] = 2,y[1] = y[2] = 1;
for(int i = 3;i <= n;i ++){
f(i);
}
for(int i = y[n];i >= 1;i --){
cout << x[n][i];
}
return 0;
}