"Topic link": Click here~~
"The main idea": Test Instructions: You have a width of 1, the height of a given continuous plank, each can brush a horizontal or a vertical column, ask you to brush at least a few times.
Sample Input
Input
52 2 1) 2 1
Output
3
Input
22 2
Output
2
Input
15
Output
1
Search:
C#ifndef _glibcxx_no_assert#include <cassert> #endif # include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath># Include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio > #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103l#include < ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool># Include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif//C + + #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception># Include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd > #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream># Include <stack> #include <stdexcept> #include <streambuf> #include <string> #include < typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103l# Include <array> #include <atomic> #include <chrono> #include <condition_variable> #include < forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random > #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error># Include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include < unordered_map> #include <unordered_set> #endifusing namespace std; #define REP (i,j,k) for (iNT I=j;i<=k;++i) #define PER (i,j,k) for (int i= (int) j;i> (int) k;--i) #define LOWBIT (a) A&-a#define Max (A, B) a >b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) typedef long Long ll;typedef unsigned long Long llu;typedef double db;const int n=5*1e3+10; LL n,m,t,ans,res,cnt,tmp; LL Num[n];char Str[n];bool vis[n];int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};int dir8[8][2]= {{1,0},{1,1},{0,1},{- 1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; ll Dfs (ll left,ll right) {ll heng=0,temp=left; LL min_gun=*min_element (num+left,num+right+1); Rep (i,left,right) {num[i]-=min_gun; } rep (I,left,right) {if (num[i]==0) {Heng+=dfs (temp,i-1); temp=i+1; }} if (Temp<=right) Heng+=dfs (temp,right); return min (heng+min_gun,right-left+1);} int main () {while (scanf ("%lld", &n)!=eof) {Rep (i,0,n-1) {scanf ("%lld", &num[i]); } LL Result=dfs (0,n-1); printf ("%lld\n", result); } return 0;} /* First find the N-bar of the shortest bar I, and then subtract its value, then look for 1 to i-1, and i+1 to the minimum value of n, because can be vertical brush, so compared to brush the interval of the horizontal brush and vertical brush the minimum value. The answer is ultimately. 52 2 1 2 151 2 3 2 153 2 1 2 3335*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces Round #256 (Div. 2) C. Painting Fence (search or DP)