Test instructions: Given a sequence of length n, let you ask for one and the largest increment sequence.
Analysis: A look, is not much like Lis Ah, this is basically the same, just change it, d (i) indicates the number of the first I, the largest and and is increasing,
If D (j) + A[i] > D (i) d (i) = d (j) + A[i] (this is guaranteed and maximum), then how is it incremented? It's simple, like Lis.
Plus a[i] > a[j], it's OK.
The code is as follows:
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <map > #include <string> #include <cctype> #include <set>using namespace Std;const int maxn = + 10;int A [MAXN], D[maxn];int main () { int n; while (scanf ("%d", &n) && N) { a[0] = 0; int m =-1; for (int i = 0; i < n; ++i) { scanf ("%d", &a[i+1]); m = max (M, a[i+1]); } memset (d, 0, sizeof (d)); for (int i = 1; I <= n; ++i) { d[i] = a[i]; for (int j = 1; j < i; ++j) { if (A[i] > A[j]) { if (D[j] + a[i] > D[i]) { d[i] = A[i] + d[j]; m = max (M, D[i]); }}} printf ("%d\n", m); } return 0;}
HDU 1087 Super jumping! jumping! jumping! (Dp+lis)