Poj 1952 buy low, buy lower maximum descent sub-sequence count, pojlower
Question:
Calculate the maximum length and number of sub-sequences for n.
Analysis:
Dp to avoid repeated Counting during counting.
Code:
// Poj 1952 // sep9 # include <iostream> using namespace std; const int maxN = 5012; int a [maxN]; int dp [maxN]; int num [maxN]; int main () {int I, j, n, ans = 0, ansNum = 0; scanf ("% d", & n); for (I = 1; I <= n; ++ I) scanf ("% d", & a [I]); for (I = 1; I <= n; ++ I) {dp [I] = 1; num [I] = 1; for (j = I-1; j> = 0; -- j) if (a [j]> a [I]) {if (dp [j] + 1 = dp [I]) num [I] + = num [j]; else if (dp [j] + 1> dp [I]) {dp [I] = dp [j] + 1; num [I] = num [j];} else if (a [j] = a [I]) {if (dp [I] = 1) num [I] = 0; break ;} ans = max (ans, dp [I]);} for (I = 1; I <= n; ++ I) if (dp [I] = ans) ansNum + = num [I]; printf ("% d", ans, ansNum); return 0 ;}