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
−10
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 字符与字节 json序列和反序列及支持的类型
b = b"demo" s = "demo" # 字符串转字节 s = bytes(s, encoding = "utf8") s = st ...
- 1.1 NLP基础技能,字符串的处理
#!/usr/bin/env python # coding: utf-8 # # 字符串操作 # ### 去空格和特殊字符 # In[8]: s = " hello world! &quo ...
- Java以组的数量将字符串分组
package org.jimmy.autosearch2019.test; import java.util.ArrayList; public class Test20190327 { publi ...
- 通过java反射机制,获取对象的属性和值(包括所有继承的父类)
java的反射机制提供了两种方法: getDeclaredFields() :该方法能获取到本类的所有属性,包括private,protected和public,但不能获取到继承的父类的属性. get ...
- MATLAB读取每个文件夹下的badcsv文件后合并为总的badexcel文件
clear; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取子文件夹中bad.csv数据%并把所有数据写到一个excel文件中%%%%%%%%%%%%%%%%%% ...
- js模块化入门与commonjs解析与应用
JS模块化的基本原理 commonjs规范 commonjs在前端模块化中的基本使用 AMD与CMD规范剖析博客链接 一.JS模块化基本原理 在JS没有提出来模块化的时候,开发JS项目比较简单,同时也 ...
- docker guide
centos docker community version install: yum -y install docker # install docker systemctl start dock ...
- 《发际线总是和我作队》第八次团队作业:Alpha冲刺 第五天
项目 内容 这个作业属于哪个课程 软件工程 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺实验十一 团队作业7:团队项目设计完善&编码 团队名称 发际线总和我作队 作业学 ...
- 前端学习日记-vue cli3.0环境搭建
卸载老版本的 vue-cli : npm uninstall vue-cli -g 安装新版本的 : npm install -g @vue/cli --安装新版本cli 同时nodeJS 要更新至 ...
- Gameia
F - Gameia HDU - 6105 Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes l ...