Codeforces 448C Painting Fence

Source: Internet
Author: User

Brush the fence, only horizontal and vertical, vertical is certainly the most is N, another so every time the bottom of the brush off, brush off, continue to brush off the above, each time the remaining press sideways or vertical brush

It's a split treatment.

#include <cstdio> #include <cstring> #include <algorithm> #include <vector>using namespace std; #define INF 0x7f7f7f7fint a[6000];int n;int ans;int len;int dfs (int l,int r) {    int i,mina = INF;    int sum = 0;    for (i = L;i <= r; i++)        mina = min (mina,a[i]);    for (i = L;i <= r; i++)        a[i]-= mina;    sum = mina;    int ll = l;    for (i = L;i <= r; i++)    {        if (a[i] = = 0)        {            sum + = DFS (ll,i-1);            ll = i+1;        }    }    if (ll <= r) sum + = DFS (ll,r);    return min (sum,r-l+1);} int main () {    int n,i;    while (~SCANF ("%d", &n))    {for        (i=0;i<n;i++)            scanf ("%d", &a[i]);        printf ("%d\n", DFS (0,n-1));    }    return 0;}

Codeforces 448C Painting Fence

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.