Last active
August 29, 2015 14:18
-
-
Save nbdd0121/25fc6ac5f45a86f36ccf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
int main(){ | |
int length; | |
std::cin >> length; | |
int* data = new int[length]; | |
for(int i=0;i<length;i++){ | |
std::cin >> data[i]; | |
} | |
std::vector<int> current; | |
std::vector<int> best; | |
for(int i=0;i<length-1;i++){ | |
for(int j=i+1;j<length;j++){ | |
current.clear(); | |
int c1 = data[i]; | |
int c2 = data[j]; | |
current.push_back(c1); | |
current.push_back(c2); | |
int c3 = c1 + c2; | |
for(int k = j;k<length;k++){ | |
if(data[k]==c3){ | |
current.push_back(c3); | |
c1=c2; | |
c2=c3; | |
c3=c1+c2; | |
} | |
} | |
if(current.size()>best.size()){ | |
best.swap(current); | |
} | |
} | |
} | |
std::cout << best.size() << std::endl; | |
for (int i=0;i<best.size();i++) | |
std::cout << best[i] << ' '; | |
std::cout << std::endl; | |
delete[] data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment