又是自己改了半天的一道题,忘了……
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include<iostream> #include<string> #include<algorithm> using namespace std; int n=1; int arr[100005]; int f[100005]; int f2[100005]; int main() { while (cin >> arr[n])n++; n--; arr[0] = 50001; f[0] = 0; for (int i = 1; i <= n; i++) { int m = f[0]; for (int j = 1; j < i; j++) { if (f[j]>m&&arr[j]>=arr[i]) { m = f[j]; } } f[i] = m + 1; } cout << *max_element(f+1,f+n+1) << endl; arr[0] = 0; f2[0] = 0; for (int i = 1; i <= n; i++) { int m = f2[0]; for (int j = 1; j < i; j++) { if (f2[j]>m&&arr[j]<arr[i]) { m = f2[j]; } } f2[i] = m + 1; } cout << *max_element(f2+1,f2+n+1) << endl; } |