Codeforces round #256 (Div. 2)

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.