Last active
August 29, 2015 14:06
-
-
Save gitzhou/1a0de83235effd950b49 to your computer and use it in GitHub Desktop.
max-length-of-none-desc-sequence
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 <algorithm> | |
using namespace std; | |
int main(int argc, const char * argv[]) { | |
const int COUNT = 10; | |
int sequence[COUNT] = {7, 3, 4, 5, 1, 4, 2, 4, 6, 3}; | |
int length[COUNT]; | |
for (int i = 0; i < COUNT; ++i) { | |
int max = 1; | |
for (int j = 0; j < i; ++j) { | |
if (sequence[i] >= sequence[j] && length[j] + 1 > max) { | |
max = length[j] + 1; | |
} | |
} | |
length[i] = max; | |
} | |
cout << "原数组: "; | |
for (int i = 0; i < COUNT; ++i) { | |
cout << sequence[i] << ' '; | |
} | |
cout << endl; | |
cout << "计算值: "; | |
for (int i = 0; i < COUNT; ++i) { | |
cout << length[i] << ' '; | |
} | |
cout << endl; | |
cout << *max_element(length, length + COUNT) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
=== 输出 ===
原数组: 7 3 4 5 1 4 2 4 6 3
计算值: 1 1 2 3 1 3 2 4 5 3
5