题解 | #最大上升子序列和#
最大上升子序列和
https://www.nowcoder.com/practice/dcb97b18715141599b64dbdb8cdea3bd
#include <cstdio> #include <algorithm> using namespace std; int main() { int n, num = 0; int arr[2000] = {0}; int arr2[2000] = {0}; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (int i = 0; i < n; i++) { arr2[i] = arr[i]; for (int j = 0; j < i; j++) { if (arr[i] > arr[j]) { arr2[i] = max(arr2[i], arr[i] + arr2[j]); } num = max(arr2[i], num); } } printf("%d", num); } }