AcWing 4007. 非零段划分
原题链接
中等
作者:
尘轩
,
2024-11-20 16:44:11
,
所有人可见
,
阅读 2
暴力模拟(70分)
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 500010;
int n;
int a[N];
int find(int b[]) {
int num = 0;
int i = 0, j = 0;
while (i < n) {
if (b[i] != 0) {
num ++;
j = i + 1;
while (j < n && b[j] != 0) j ++;
i = j;
}
else i ++;
}
return num;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i ++) scanf("%d", &a[i]);
int res = find(a);
for (int i = 0; i < n; i ++) {
int b[N];
memcpy(b, a, sizeof a);
if (a[i]) {
for (int j = 0; j < n; j ++)
if (b[j] < a[i]) b[j] = 0;
res = max(res, find(b));
}
}
cout << res << endl;
return 0;
}