最长上升子序列

参考POJ 2533, 1836, 1887

 

下面附1887代码,

#include <iostream> #include <algorithm> using namespace std; int N; int data[100001]; int maxLen[100001]; void compute(int c) { maxLen[N] = 1; for(int i = N - 1; i >= 1; i--) { int max = 0; for(int j = N; j > i; j--) { if (data[i] > data[j]) { if(maxLen[j] > max) { max = maxLen[j]; } } } maxLen[i] = max + 1; } cout << "Test #" << c << ":" << endl; cout << " maximum possible interceptions: " << *max_element(maxLen + 1, maxLen + N + 1) << endl; cout << endl; } int main() { int n; int c = 0; cin >> n; while(n != -1) { int index = 0; while(n!= -1) { data[++index] = n; cin >> n; } N = index; c++; compute(c); cin >> n; } }

你可能感兴趣的:(c)