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

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
题意: 给一个数组a[n],问使数组中某一个值变成P。得到a[l]+a[l+1]+......+a[r]最大是多少。

#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&#39;s Array的更多相关文章

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

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

  2. hdu 5280 Senior's Array

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

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

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

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

  5. HDU5280 Senior&#39;s Array(简单DP)

    题目链接:pid=5280">传送门 题意: 给定一个长度为n的序列,和一个改动的值p,必须从原序列中选一个位置改动成p, 求改动后的区间和的最大值. 分析: 枚举位置+最大区间和. ...

  6. HDU 5281 Senior&#39;s Gun

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

  7. HDU 5281 Senior&#39;s Gun 杀怪

    题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...

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

  9. hdu 5281 Senior's Gun

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

随机推荐

  1. Comparator.comparing比较排序

    使用外部比较器Comparator进行排序 当我们需要对集合的元素进行排序的时候,可以使用java.util.Comparator 创建一个比较器来进行排序.Comparator接口同样也是一个函数式 ...

  2. Vue构建命令

    node -v npm -v vue -V npm install vue (这个命令不行) 提示信息:+ vue@2.6.10 updated 1 package and audited 1 pac ...

  3. dockerfile 的最佳实践

    Dockerfile 编写nginx容器 [root@mast nginx]# cat Dockerfile FROM centos MAINTAINER zhaoruidong RUN yum -y ...

  4. Java数据结构和算法(一)--栈

    栈: 英文名stack,特点是只允许访问最后插入的那个元素,也就是LIFO(后进先出) jdk中的stack源码: public class Stack<E> extends Vector ...

  5. Failed to load class “org.slf4j.impl.StaticLoggerBinder”

    背景: 在配置使用Hibernate的时候遇到了这个问题, 然后就很头疼. SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerB ...

  6. executeFind(XXX) is undefined for the type hibernateTemplate(大概是这个错误吧)

    两句话,jar包版本不一样,类中包含的方法可能有改变. 出错时用的是spring5.x版本,但是没有找到我的api.(不记得放在那里了),所以换了spring的版本(换成了spring3.x).问题解 ...

  7. java登录拦截Filter

    此例子为一个简单的登录拦截. 首先在web.xml中配置拦截类. <filter-mapping> <filter-name>SessionFilter</filter- ...

  8. Web前端技术体系大全搜索

    一.前端技术框架 1.Vue.js 官网:https://cn.vuejs.org/ Vue CLI:https://cli.vuejs.org/ 菜鸟教程:http://www.runoob.com ...

  9. 去除ie下select框箭头

    select::-ms-expand { display: none;}兼容ie10及以上

  10. AES/DES 可逆性加密算法 -- java工具类

    package com.lock.demo.service; import org.apache.tomcat.util.codec.binary.Base64; import javax.crypt ...