hdu 5280 Senior's Array
题目连接
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的更多相关文章
- HDU 5280 Senior's Array (暴力,水)
题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. #include < ...
- HDU 5280 Senior's Array
Senior's Array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- HDU 5280 Senior's Array 最大区间和
题意:给定n个数.要求必须将当中某个数改为P,求修改后最大的区间和能够为多少. 水题.枚举每一个区间.假设该区间不改动(即改动该区间以外的数),则就为该区间和,若该区间要改动,由于必须改动,所以肯定是 ...
- 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 ...
- hdu 5281 Senior's Gun
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...
- hdu 5282 Senior's String 两次dp
题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...
- 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 ...
- hdu 5532 Almost Sorted Array
http://acm.hdu.edu.cn/showproblem.php?pid=5532 题目大意: 给你一个不规则的序列,问是否能够通过删除一个元素使其成为一个有序的序列(递增或递减(其中相邻 ...
- hdu 5532 Almost Sorted Array(模拟)
Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, ...
随机推荐
- 华为OJ平台——计算字符串的相似度
题目描述: 对于不同的字符串,我们希望能有办法判断相似程度,我们定义了一套操作方法来把两个不相同的字符串变得相同,具体的操作方法如下: 1 修改一个字符,如把“a”替换为“b”. 2 增加一个字符,如 ...
- Android学习笔记之AndroidManifest.xml文件解析
一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...
- Devexpress中WebChartControl控件柱状统计图的做法(数据为调用存储过程)
//前台控件代码:WebChartControl控件: <%-- 月采购量统计--%> <dxchartsui:WebChartControl ID="WebChartCo ...
- javascript 实现HashTable(哈希表)
一.javascript哈希表简介 javascript里面是没有哈希表的,一直在java,C#中有时候用到了这一种数据结构,javascript里面若没有,感觉非常不顺手.细细看来,其实javasc ...
- 转载 《AngularJS》5个实例详解Directive(指令)机制
<AngularJS>5个实例详解Directive(指令)机制 大漠穷秋 本文整理并扩展了<AngularJS>这本书第六章里面的内容,此书近期即将由电子工业出版社出版,敬请 ...
- ibatis 改下数据库连接
<!--<dataSource name="iBatisNet" connectionString="data source= DESKTO ...
- JS常用的设计模式(11)—— 中介者模式
中介者对象可以让各个对象之间不需要显示的相互引用,从而使其耦合松散,而且可以独立的改变它们之间的交互. 打个比方,军火买卖双方为了安全起见,找了一个信任的中介来进行交易.买家A把钱交给中介B,然后从中 ...
- Bypass pattern lock on Sony Xperia Z2 and backup all data
Yesterday she came to me with a Sony Xperia Z2 D6503. Guess what? She forgot the pattern so she coul ...
- Android IOS WebRTC 音视频开发总结(三十)-- ice协议异同
本文主要介绍ICE与SDP交互过程中的一些知识,支持原创,文章来博客园RTC.Blacker,转载请说明出处. 用过libjingle模块的同学都知道连接过程中candidate的获取与连接流程,一边 ...
- [转]基于AnyCAD的准双曲面齿轮建模
基于AnyCAD的准双曲面齿轮建模 作者:谨阳 (文章来源:http://www.opencascade.net/ask/?/article/6) 摘要:根据准双面齿轮的加工方法和传动特性,对准双面齿 ...