Bài viết: 28 



Link bài:
Thuật toán:
Code:
Thuật toán:
- Ta duyệt mảng từ 3 tới n (Vì dãy có tính chất Fibonanci chỉ được xác định với 3 phần tử trở lên và tính chất chỉ có thể xác định khi có ít nhất 3 phần tử).
- So sánh và chọn ra độ dài lớn nhất ta tìm được.
Code:
Mã:
#include <bits/stdc++.h>
using namespace std;
int ans, n;
int a[30007];
void brow(int pos){
int ps = pos;
while (ps <= n){
// cout << ps << endl;
int prans = 2;
while (a[ps] == (a[ps-1] + a[ps-2])) {prans++; ps++;}
ps++;
ans = max(ans, prans);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("daso.inp", "r", stdin);
//freopen("daso.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
brow(3);
if (ans == 2) cout << -1; else cout << ans;
return 0;
}