wyc20110914 @ 2023-06-20 21:36:20
#include<bits/stdc++.h>
using namespace std;
int f[10001];
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 Zelensky @ 2023-06-20 21:39:22
应该要高精度吧
by Li_mz__ @ 2023-06-20 21:39:41
@wyc20110914 我的
by wyc20110914 @ 2023-06-20 21:40:04
@Li_mz__ 我这只输出f[i]的第n项,没错吧
by Li_mz__ @ 2023-06-20 21:40:55
@wyc20110914 感觉是对的
by wyc20110914 @ 2023-06-20 21:41:38
@Li_mz__ 真搞不懂哪错了
by Li_mz__ @ 2023-06-20 21:43:27
@wyc20110914 我和你代码差不多一样,f[3]=3, i可以直接等于四,但是for循环前面要加
f[3]=3;
by wyc20110914 @ 2023-06-20 21:43:41
@Zelensky 这题不用高精度吧,你过了吗
by wyc20110914 @ 2023-06-20 21:44:03
@Li_mz__ 我试试
by Li_mz__ @ 2023-06-20 21:44:50
@wyc20110914
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n,arr[55];
cin>>n;
arr[1] = 1;
arr[2] = 2;
arr[3] = 3;
for(long long i = 4;i <= n;i++){
arr[i] = arr[i - 1] + arr[i - 2];
}
cout<<arr[n];
return 0;
}
by wyc20110914 @ 2023-06-20 21:45:07
@Li_mz__ 还没过,给我看看你咋写的。