HDU 5280 Senior's Array
Senior's Array
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 528 Accepted Submission(s): 209
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).
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。
2
3 5
1 -1 2
3 -2
1 -1 2
8
2
#include<stdio.h>
const int N = 1005;
const int inf = 1<<29;
int main(){
__int64 dp[N],P,a[N],ans;
int n,T;
scanf("%d",&T);
while(T--){
scanf("%d%I64d",&n,&P);
for(int i=1; i<=n; i++)
scanf("%I64d",&a[i]); ans=-inf;
dp[0]=0; for(int i=1; i<=n; i++)
{
int tmp=a[i];
a[i]=P;
for(int j=1; j<=n; j++)
{
if(dp[j-1]>0)
dp[j]=dp[j-1]+a[j];
else
dp[j]=a[j];
if(dp[j]>ans)
ans=dp[j];
}
a[i]=tmp;
}
printf("%I64d\n",ans);
}
}
HDU 5280 Senior's Array的更多相关文章
- HDU 5280 Senior's Array 最大区间和
题意:给定n个数.要求必须将当中某个数改为P,求修改后最大的区间和能够为多少. 水题.枚举每一个区间.假设该区间不改动(即改动该区间以外的数),则就为该区间和,若该区间要改动,由于必须改动,所以肯定是 ...
- hdu 5280 Senior's Array
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...
- HDU 5280 Senior's Array (暴力,水)
题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. #include < ...
- 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 ...
- HDU5280 Senior's Array(简单DP)
题目链接:pid=5280">传送门 题意: 给定一个长度为n的序列,和一个改动的值p,必须从原序列中选一个位置改动成p, 求改动后的区间和的最大值. 分析: 枚举位置+最大区间和. ...
- HDU 5281 Senior's Gun
Senior's Gun Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 5281 Senior's Gun 杀怪
题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...
- 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 ...
随机推荐
- 植物大战僵尸游戏的开发(python)
装备东西: 搭建好python环境, 四张图片,(背景图片,炮弹图片,僵尸图片,豌豆图片),就ok了 没有安装pygame的需要进行安装 pip install pygame 参考视频 # 植物大 ...
- jeecms
===标签=== <!-- 显示一级栏目对应的二级栏目 --> <!-- [@cms_channel_list parentId=c.id] [#if tag_list?size&g ...
- du - 报告磁盘空间使用情况
总览 du [options] [file...] POSIX 选项: [-askx] GNU 选项 (最短格式): [-abcDhHklLmsSxX] [--block-size=size] [-- ...
- JS 中的事件绑定、事件监听、事件委托是什么?
在JavaScript的学习中,我们经常会遇到JavaScript的事件机制,例如,事件绑定.事件监听.事件委托(事件代理)等.这些名词是什么意思呢,有什么作用呢? 事件绑定 要想让 JavaScri ...
- 和为S
2518 和为S 2 秒 262,144 KB 10 分 2 级题 小b有一个01序列A,她想知道A有多少个非空连续子序列和为S. 你能帮帮她吗? 收起 输入 第一行输入一个数n,表示A的长度 ...
- delphi jinchengneicun
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Configuring_the_Memory_Manager https://docs.micros ...
- vue计算属性computed和methods的区别
computed和methods的区别 在new Vue的配置参数中的computed和methods都可以处理大量的逻辑代码,但是什么时候用哪个属性,要好好区分一下才能做到正确的运用vue. com ...
- Jenkins出现 {"changed": false, "msg": "mkdir: cannot create directory ‘/root/.ansible/tmp/ansible-tmp-1552390265.8-253945919613076’: No space left on device\n", "unreachable": true}
之前部署Jenkins没有遇到过这个问题,百度也找不到相关内容,无奈用过google翻译了一下,显示内存不足,上到服务器查询df -h 发现use% 100% 由于日志等文件导致服务器磁盘空间满了,引 ...
- 杭电 1213 How Many Tables (并查集求团体数)
Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius ...
- 修改centos的yum源为国内的源
1.安装Centos后默认的Yum源如下 ll /etc/yum.repos.d/ [root@localhost ~]# ll /etc/yum.repos.d/ total 32 -rw-r- ...