4007. 非零段划分 - AcWing题库
可以拿70分的做法-暴力枚举。
枚举每个数设为p。
n是1e3,每个数是1e4,1e3*1e4是1e7。
code
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int a[N];
int ans;
int main()
{
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int p=1;p<=N;p++)
{
int cnt=0;
for(int i=1;i<=n;i++)
{
if(a[i]<p)a[i]=0;
if(!a[i-1]&&a[i])cnt++;
}
ans=max(ans,cnt);
}
cout<<ans<<endl;
return 0;
}