Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1087
is to seek the longest ascending subsequence, but the result is the and of the sequence, the transfer equation: dp[i] = max (Dp[i], dp[j]+a[i])
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <iostream>6#include <cmath>7#include <queue>8#include <map>9#include <Set>Ten#include <stack> One#include <list> A#include <vector> - - using namespacestd; the -InlineintMaxintAintb) { - returna > B?a:b; - } + Const intMAXN =1010; - intN; + intA[MAXN]; A intDP[MAXN]; at intans; - intMain () { - //freopen ("in", "R", stdin); - while(~SCANF ("%d", &n) &&N) { -Ans =0; - for(inti =0; I < n; i++) { inscanf"%d", &a[i]); - } to for(inti =0; I < n; i++) { +Dp[i] =A[i]; - for(intj =0; J < I; J + +) { the if(A[j] <A[i]) { *Dp[i] = max (Dp[i], dp[j] +a[i]); $ }Panax Notoginseng } -Ans =Max (ans, dp[i]); the } +printf"%d\n", ans); A } the}
[HDOJ1087] Super jumping! jumping! jumping!