Back
DayCon.cpp
Save
// DayCon.cpp #include
using namespace std; int n = 10; int a[100] = {0, 1, 8, 3, 4, 9, 10, 5, 11, 7}; int L[100], T[100]; void DayCon() { a[0] = INT_MIN; a[n] = INT_MAX; L[n] = 1; for (int i = n - 1; i >= 0; i--) { int jmax = n; for (int j = i; j <= n; j++) if (a[j] > a[i] && L[j] > L[jmax]) jmax = j; L[i] = L[jmax] + 1; T[i] = jmax; } } void TruyVet() { cout << "i\t"; for (int i = 0; i <= n; i++) { cout << i << "\t"; } cout << endl; cout << "a[i]\t"; for (int i = 0; i <= n; i++) { if (i == 0 || i == n) cout << "*\t"; else cout << a[i] << "\t"; } cout << endl; cout << "L[i]\t"; for (int i = 0; i <= n; i++) { cout << L[i] << "\t"; } cout << endl; cout << "T[i]\t"; for (int i = 0; i < n; i++) { cout << T[i] << "\t"; } cout << endl; int k = T[0]; cout << "Day con: "; while (k != n) { cout << "a[" << k << "]: " << a[k] << " "; k = T[k]; } } int main() { DayCon(); TruyVet(); return 0; }