Codeforce 448c fill Problem

Source: Internet
Author: User

Question:
There are multiple pieces of wood to be filled, you can apply a row at a time, you can also apply a column at a time, of course, when you paint a line of wood piece with insufficient length in the middle, fill in to this interruption

 

This topic can be easily solved by using DFS, although it is still very difficult to understand.

 

1 # include <iostream> 2 3 using namespace STD; 4 5 # define n 5010 6 int A [n], n; 7 8 int min (int c, int D) 9 {10 return C <D? C: D; 11} 12 int dfs (int c, int D, int X) // get the part from C to D, perform at least several operations 13 {14 if (C> d) return 0 after the x length has been fully filled in; // when the C ratio is D, do not fill it out, so return 015 int T = C, K = A [c]; 16 for (INT I = C; I <= D; I ++) 17 if (a [I] <k) 18 k = A [I], t = I; // find the shortest D 19 Return min (DFS (C, T-1, a [T]) of the wood in C to D + A [T]-x + DFS (t + 1, D, a [T]), D-C + 1); // One is a horizontal query, one is vertical, get the minimum 20} 21 int main () 22 {23 while (CIN> N) {24 for (INT I = 0; I <N; I ++) CIN> A [I]; 25 cout <DFS (0, n-1, 0) <Endl; 26} 27 28 return 0; 29}

 

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.