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. Android(java)学习笔记159:多线程断点下载的原理(Android实现)

    之前在Android(java)学习笔记215中,我们从JavaSE的角度去实现了多线程断点下载,下面从Android角度实现这个断点下载: 1. 新建一个Android工程: (1)其中我们先实现布 ...

  2. nginx 新手入门

    Nginx 是一个高性能的http 和反向代理服务器,也是一个代理服务器. Nginx比Apache 更加轻量级,占用的资源少,抗并发,二apache是阻塞型的,在高并发下,nginx更占优势. 我们 ...

  3. uva1228 Integer Transmission

    这道题思维很灵活.也有点套路的意思. 首先规定0,1分别按照原来的顺序接收,只是01换位.这样简化了思维.(否则并不会有更优结果它.,比较好想)最大值和最小值可以贪心得到.那么接下来就是给定一个整数P ...

  4. 数组、list排序

    //数字排序 int[] intArray = new int[] {4, 1, 3, -23}; Arrays.sort(intArray); 输出: [-23, 1, 3, 4] //字符串排序, ...

  5. Oracle中的DDL,DML,DCL总结

    转自http://blog.csdn.net/w183705952/article/details/7354974 DML(Data Manipulation Language,数据操作语言):用于检 ...

  6. luogu P1407 稳定婚姻-tarjan

    题目背景 原<工资>重题请做2397 题目描述 我国的离婚率连续7年上升,今年的头两季,平均每天有近5000对夫妇离婚,大城市的离婚率上升最快,有研究婚姻问题的专家认为,是与简化离婚手续有 ...

  7. while循环处理列表和字典

    一.在列表之间移动元素 假设有一个列表,里面存放的是网站新注册但没有验证的用户,验证这些用户后,如何将它们移动到另一个已验证用户列表中呢? 其中一种方法是使用while循环,在验证用户的同时,将其从未 ...

  8. 大数据学习——关于hive中的各种join

    准备数据 2,b 3,c 4,d 7,y 8,u 2,bb 3,cc 7,yy 9,pp 建表: create table a(id int,name string) row format delim ...

  9. 大数据学习——hive的sql练习

    1新建一个数据库 create database db3; 2创建一个外部表 --外部表建表语句示例: create external table student_ext(Sno int,Sname ...

  10. HDU2069-Coin Change

    Coin Change 这题题意和UVA674很像,但加了一个限制条件不能超过100个硬币.于是我们可以用d[i][j]来表示硬币数量为i时金钱总数为j时的方法总数,总钱不能超过250. const ...