Skip to content

Instantly share code, notes, and snippets.

@gitzhou
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitzhou/1a0de83235effd950b49 to your computer and use it in GitHub Desktop.
Save gitzhou/1a0de83235effd950b49 to your computer and use it in GitHub Desktop.
max-length-of-none-desc-sequence
#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;
}
@gitzhou
Copy link
Author

gitzhou commented Sep 26, 2014

=== 输出 ===
原数组: 7 3 4 5 1 4 2 4 6 3
计算值: 1 1 2 3 1 3 2 4 5 3
5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment