Created
January 6, 2014 05:16
-
-
Save codyhan94/8278605 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
int f(const vector<int> &x) | |
{ | |
int longest = 2; | |
int p = 0; | |
int q = 0; | |
while (q < x.size()) | |
{ | |
int len = q - p + 1; | |
if (admissible(x, p, q)) | |
{ | |
if (len > longest) | |
{ | |
longest = len; | |
} | |
} | |
else | |
{ | |
p = q; | |
} | |
q++; | |
} | |
} | |
bool admissible(const vector<int> &x, int p, int q) | |
{ | |
if ((p == q) || (q == p + 1)) { return true; } | |
if (x[q - 2] + x[q - 1] == x[q]) { return true ;} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment