General Solution:
D: Increase K. If we perform binary enumeration, if there is an O (n) method for statistics, it will be OK. First, enumerate, the statistics for each row can reach O (1), so it is easy.
E: I have some ideas, but the code is too weak and the DFS is too easy to learn.
We found that it is actually a deep recursive structure with only 100000 elements, so this is a breakthrough point.
Find all the factors first, and then enumerate the factors. If it appears, perform in-depth traversal. The end condition is to reach the K layer or the factor is 1. Note: When k is greater than 100000, it must be changed to 100000, because the number of layers cannot exceed 100000;
C: Divide and conquer + greedy.
This is really a good question. The idea of the question is: greedy for the interval (L, R). Compared with the value of R-l + 1, it is recursive and the specific code is given.
# Include <stdio. h> # include <string. h ># include <iostream> using namespace STD; int N; int A [123456]; int DFS (int l, int R) {If (L> r) return 0; int Mm = 9999999; int Pos; For (INT I = L; I <= r; I ++) if (MM> A [I]) {mm = A [I]; Pos = I;} int ans = 0; For (INT I = L; I <= r; I ++) A [I]-= mm; ans + = DFS (L, pos-1); ans + = DFS (Pos + 1, R); Return min (ANS, r-l + 1);} int main () {int N; CIN> N; For (INT I = 1; I <= N; I ++) cin> A [I]; cout <DFS (1, N) <Endl; return 0 ;}