送分题

用暴力,枚举一个修改的,算最大子段和,o(n)2的复杂度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<cstdio>
#include<iostream>
using namespace std;
int a[99999];
int s;int n,p;
int main(){
freopen("songfen.in","r",stdin);
freopen("songfen.out","w",stdout);
scanf("%d%d",&n,&p);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int maxn=-9999999;
for(int i=1;i<=n;i++)
{
s=0;
for(int j=1;j<=n;j++)
{

s=s+(j!=i?a[j]:p);
maxn=max(s,maxn);
if(s<0)s=0;
}

}
printf("%d",maxn);

fclose(stdin);
fclose(stdout);
}

最近的文章

啦啦啦啦啦

stick木棍(stick) 思路:先把奇数个的削掉,因为奇数个的不可能组成长方形,削掉有可能然后削完的用贪心,最大的组成正方形一定最大。123456789101112131415161718192021222324252627#include&lt;cstdio&gt;#include&lt;io …

于  爆搜题 继续阅读
更早的文章

bzoj3713

斐波那契亚数列,直接暴力就行了,我是预处理出来,在输出,类似于桶排12345678910111213141516171819202122232425262728293031323334#include&lt;cstdio&gt;#include&lt;iostream&gt;#include&lt; …

于  暴力 继续阅读