Question: In a sequence, each element must be at least two times ahead of each other. The maximum value is N. How many ships of this type have a length of L.
Analysis: DP and Lis.
State: the number of sequences whose end number of f (I, j) is J and whose length is I. There is a transfer equation:
F [I] [J] = sum (F [I-1] [k]) {2 ^ (I-2) <= k <= J/2 );
Use s [I] [J] To find the number of strings whose length is I and cannot exceed J.
Note ).
# Include <iostream> # include <cstdlib> # include <cstring> using namespace STD; long f [11] [2001]; long s [11] [2001]; int main () {// name the memset (F, 0l, sizeof (f); memset (S, 0l, sizeof (s )); f [0] [0] = 1l; For (INT I = 1; I <= 10; ++ I) for (Int J = (1 <(I-1 )); j <= 2000; ++ J) {for (int K = (1 <(I-1)/2; k <= (j> 1); ++ K) f [I] [J] + = f [I-1] [k]; s [I] [J] = s [I] [J-1] + F [I] [J];} // int t, n, m; while (CIN> T) for (INT c = 1; C <= T; ++ c) {CIN> N> m; cout <"case" <C <": N =" <n <", M =" <m <", # lists = "<s [N] [m] <Endl;} return 0 ;}
Zoj 2402-Lenny's lucky lotto lists