题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5280

Senior's Array

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\leq n\leq 1000$, $-10^9\leq A[i], P\leq 10^9$。

Output

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

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

Sample Output

8
2

数据才1000直接暴力。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using std::max;
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::map;
using std::pair;
using std::vector;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
const int INF = 0x7fffffff;
typedef long long ll;
ll p, ans, arr[N], sum[N];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int t, n;
scanf("%d", &t);
while (t--) {
ans = -INF;
scanf("%d %lld", &n, &p);
rep(i, n) scanf("%lld", &arr[i]);
rep(i, n) {
ll tmp = arr[i]; arr[i] = p;
rep(j, n) {
sum[j] = sum[j - ] > ? sum[j - ] + arr[j] : arr[j];
ans = max(ans, sum[j]);
}
arr[i] = tmp;
}
printf("%lld\n", ans);
}
return ;
}

hdu 5280 Senior's Array的更多相关文章

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

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

  2. HDU 5280 Senior&#39;s Array

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

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

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

  4. 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 ...

  5. hdu 5281 Senior's Gun

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...

  6. hdu 5282 Senior&#39;s String 两次dp

    题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...

  7. 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  8. hdu 5532 Almost Sorted Array

    http://acm.hdu.edu.cn/showproblem.php?pid=5532  题目大意: 给你一个不规则的序列,问是否能够通过删除一个元素使其成为一个有序的序列(递增或递减(其中相邻 ...

  9. hdu 5532 Almost Sorted Array(模拟)

    Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, ...

随机推荐

  1. centos 6.5 samba简单配置

    1.安装samba yum -y install samba  (我的显示已经安装啦!) 2.编辑samba的配置文件 vi /etc/samba/smb.conf 用 testparm查看我配置后的 ...

  2. BZOJ1051 受欢迎的牛

    http://www.lydsy.com/JudgeOnline/problem.php?id=1051 Description 每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A ...

  3. 使用POI导入Excel异常Cannot get a text value from a numeric cell 解决

    POI操作Excel时因为Excel数据Cell有不同的类型,会出现Cannot get a text value from a numeric cell的异常错误. 异常原因:Excel数据Cell ...

  4. ICDM 2007

    Language-Independent Set Expansion of Named Entities Using the Web. Chao Wang, Venu Satuluri, Sriniv ...

  5. hdu 3336【Count the string】(KMP)

    一道字符串匹配的题目,仅仅借此题练习一下KMP 因为这道题目就是要求用从头开始的n个字符串去匹配原来的字符串,很明显与KMP中求next的过程很相似,所以只要把能够从头开始匹配一定个数的字符串的个数加 ...

  6. Ossim应用体验视频

    Ossim体验视频 近期,我写的有关Ossim应用的系列文章网友们非常关注,这里对大家提出有一些问题我制作了高清的视频和截图发布到网站,以让更多的人了解这款开源安全平台.在年后出版的教程中会详细讲解o ...

  7. [JFinal 2] JFinal 开发框架

    导读:在这次和大家一起开发的今日开讲后台管理系统中,我们用的是JFinal框架.开始的时候,说是用SSH,心里一阵窃喜,刚刚做了网上商城的项目,对于这个框架还算是接触过了.JFinal却是个新货,心里 ...

  8. I/O系统,多线程、图形用户界面编程

    多线程 进程与线程区别: 进程需要分配独立的内存空间:线程在同一内存空间中工作,可以共享同一块内存和系统资源 与Java相关的API: 1)Thread类 方法:start()启动: urn() : ...

  9. VS2013 试用版到期 解决办法

    摘自:http://jingyan.baidu.com/article/fec7a1e5100b481190b4e7d9.html 输入密钥:BWG7X-J98B3-W34RT-33B3R-JVYW9

  10. 基于MVC设计模式的两种软件架构简介

    第一种模式,可处理组合命令,具有撤销(Undo)和重做(Redo)功能,支持多种数据库类型     1.Action采用组合模式,既可以代表一个简单的动作,也可以代表一组动作组合.List<Ac ...