暑期训练 CF套题
作者:互联网
题意:有n个数,都是0或1,然后必须执行一次操作,翻转一个区间,里面的数0变1,1变0,求最多1的数量
思路:最开始我写的最大字段和,后面好像写搓了,然后我又改成暴力,因为这个范围只有100,写n^3都没事,所以我们第一层枚举左区间,第二层枚举右区间,然后我们第三层记录左边1的数量,中间的0的数量,右边的1的数量即可
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define maxn 100005 #define mod 1000000007 using namespace std; typedef long long ll; ll a[1005],num,n; int main(){ scanf("%lld",&n); for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); } ll mx=0; for(int i=1;i<=n;i++){ for(int j=i;j<=n;j++){ ll shu=0; for(int k=1;k<i;k++){ if(a[k]) shu++; } for(int k=i;k<=j;k++){ if(a[k]==0) shu++; } for(int k=j+1;k<=n;k++){ if(a[k]) shu++; } mx=max(shu,mx); } } printf("%lld",mx); }View Code
标签:int,ll,CF,long,define,枚举,暑期,include,套题 来源: https://www.cnblogs.com/Lis-/p/11330620.html