题目链接:Codeforces - Bear and Blocks
每个砖块被消掉有3种情况。
前面被消掉,后面被消掉,上面被消掉。
然后对三种分别dp一下即可。
AC代码:
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5+10;
int n
,a
[N
],f
[N
],g
[N
],res
;
signed main(){
cin
>>n
;
for(int i
=1;i
<=n
;i
++) scanf("%d",&a
[i
]);
for(int i
=1;i
<=n
;i
++) f
[i
]=min(a
[i
]-1,f
[i
-1])+1;
for(int i
=n
;i
>=1;i
--) g
[i
]=min(a
[i
]-1,g
[i
+1])+1;
for(int i
=1;i
<=n
;i
++) res
=max(res
,min(f
[i
],g
[i
]));
cout
<<res
;
return 0;
}
转载请注明原文地址:https://tech.qufami.com/read-7004.html