Senior's Array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 852    Accepted Submission(s): 311

Problem Description
One day, Xuejiejie gets an array A. Among all non-empty intervals of A, she wants to find the most beautiful one. She defines the beauty as the sum of the interval. The beauty of the interval---[L,R] is calculated by this formula : beauty(L,R) = A[L]+A[L+1]+……+A[R]. The most beautiful interval is the one with maximum beauty.

But as is known to all, Xuejiejie is used to pursuing perfection. She wants to get a more beautiful interval. So she asks Mini-Sun for help. Mini-Sun is a magician, but he is busy reviewing calculus. So he tells Xuejiejie that he can just help her change one value of the element of A to P . Xuejiejie plans to come to see him in tomorrow morning.

Unluckily, Xuejiejie oversleeps. Now up to you to help her make the decision which one should be changed(You must change one element).

 
Input
In the first line there is an integer T, indicates the number of test cases.

In each case, the first line contains two integers n and P. n means the number of elements of the array. P means the value Mini-Sun can change to.

The next line contains the original array.

1≤n≤1000, −109≤A[i],P≤109。

 
Output
For each test case, output one integer which means the most beautiful interval's beauty after your change.
 
Sample Input

2
3 5
1 -1 2
3 -2
1 -1 2

 
Sample Output
8
2
 
Source
/**
题意:给出一个数组,如果用p代替数组中的一个数求最大的区间和
做法:dp(比赛的时候想得太多)
**/
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#define maxn 1100
#define INF 0x7fffffff
using namespace std;
long long mmap[maxn];
long long dp[][maxn];
long long n;
long long DP()
{
dp[][] = max((long long),mmap[]);
for(int i=;i<n;i++)
{
dp[][i] = max((long long),dp[][i-] + mmap[i]);
}
long long tmp = mmap[];
for(int i=;i<n;i++)
{
dp[][i] = dp[][i-] + mmap[i];
tmp = max(tmp,dp[][i]);
}
return tmp;
}
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
//#endif // ONLINE_JUDGE
int T;
scanf("%d",&T);
while(T--)
{
long long p;
scanf("%lld %lld",&n,&p);
for(int i=;i<n;i++)
{
scanf("%lld",&mmap[i]);
}
memset(dp,,sizeof(dp));
long long res = -INF;
for(int i=;i<n;i++)
{
long long tt = mmap[i];
mmap[i] = p;
res = max(res,DP());
mmap[i] = tt;
}
printf("%lld\n",res);
}
return ;
}

HDU-5280的更多相关文章

  1. hdu 5280 Senior's Array

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...

  2. HDU 5280 Senior's Array (暴力,水)

    题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. #include < ...

  3. HDU 5280 Senior&#39;s Array 最大区间和

    题意:给定n个数.要求必须将当中某个数改为P,求修改后最大的区间和能够为多少. 水题.枚举每一个区间.假设该区间不改动(即改动该区间以外的数),则就为该区间和,若该区间要改动,由于必须改动,所以肯定是 ...

  4. HDU 5280 Senior&#39;s Array

    Senior's Array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  5. hdu 5280 贪心 O(n)算法

    题意给你一个序列A[1...N],你必须修改一个A[i]为P,使得修改后的序列A的连续最大和最大 其中N<=1000 分析,N非常小,N^2暴力随便做,不细讲 说一个O(N)的算法 我们知道O( ...

  6. HDU 5280 BestCoder Round #47 1001:Senior's Array

    Senior's Array  Accepts: 199  Submissions: 944  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit ...

  7. Bestcoder Round 47 && 48

    1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...

  8. hdu 1038 Biker&#39;s Trip Odometer(水题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1038 Biker's Trip Odometer Time Limit: 2000/1000 MS ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. 20165218 2017-2018-1 《Java程序设计》第三周学习总结

    20165218 2017-2018-1 <Java程序设计>第三周学习总结 教材学习内容总结-第四章 类与对象 面向对象语言 需要完成某种任务时,首先要想到,谁去完成任务,即哪个对象去完 ...

  2. SpringAOP简介

    AOP(Aspect Orient Programming) --- 面向切面编程 将分散在各个业务逻辑中的相同代码 通过 “横向”切割方式抽取到独立模块中 方式抽取到独立模块中;[它针对的是程序运行 ...

  3. memchr函数

    函数原型:extern void *memchr(void *str, char ch, unsigned count) 参数说明:从str所指内存区域的前count个字节查找字符ch.        ...

  4. HDU3068:最长回文(Manacher模板)

    最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. 中频IF

    Intermediate 频率是指中频. 一般RF射频有三个频率,基带频率,中频,射频. 射频是发射到空中的频率,也就是我们一般说的2.4G, Sub-1G.但这个频率太高,不利于放大器做增益控制.所 ...

  6. Spring------mysql读写分离

    1. 为什么要进行读写分离 大量的JavaWeb应用做的是IO密集型任务, 数据库的压力较大, 需要分流 大量的应用场景, 是读多写少, 数据库读取的压力更大 一个很自然的思路是使用一主多从的数据库集 ...

  7. [洛谷P3527] [POI2011]MET-Meteors

    洛谷题目链接:[POI2011]MET-Meteors 题意翻译 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1 ...

  8. WebDriver中如何处理Iframe 及 嵌套Iframe

    最近在用webdriver进行爬虫的时候,遇到了网站存在iframe的情况,处理了好久没有解决,后来发现原来webdriver自带处理方法,汗颜.. 1.iFrame有ID 或者 name的情况 // ...

  9. 20155335俞昆《java程序设计》第10周总结

    学号 2016-2017-2 <Java程序设计>第十周学习总结 ## 事实上网络编程,我们可以简单的理解为两台计算机相互通讯数据而已,对于程序员而言,掌握一种编程接口并使用一种编程模型相 ...

  10. NGINX: 反向代理 Nexus

    Nginx 反向代理 nexus 的服务, 一直卡在 Initialize... 解决方式是添加一个 header X-Forwarded-Proto: proxy_set_header X-Forw ...