Senior's Array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 852    Accepted Submission(s): 311

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
/**
题意:给出一个数组,如果用p代替数组中的一个数求最大的区间和
做法:dp(比赛的时候想得太多)
**/
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#define maxn 1100
#define INF 0x7fffffff
using namespace std;
long long mmap[maxn];
long long dp[][maxn];
long long n;
long long DP()
{
dp[][] = max((long long),mmap[]);
for(int i=;i<n;i++)
{
dp[][i] = max((long long),dp[][i-] + mmap[i]);
}
long long tmp = mmap[];
for(int i=;i<n;i++)
{
dp[][i] = dp[][i-] + mmap[i];
tmp = max(tmp,dp[][i]);
}
return tmp;
}
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
//#endif // ONLINE_JUDGE
int T;
scanf("%d",&T);
while(T--)
{
long long p;
scanf("%lld %lld",&n,&p);
for(int i=;i<n;i++)
{
scanf("%lld",&mmap[i]);
}
memset(dp,,sizeof(dp));
long long res = -INF;
for(int i=;i<n;i++)
{
long long tt = mmap[i];
mmap[i] = p;
res = max(res,DP());
mmap[i] = tt;
}
printf("%lld\n",res);
}
return ;
}

HDU-5280的更多相关文章

  1. hdu 5280 Senior's Array

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

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

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

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

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

  4. HDU 5280 Senior&#39;s Array

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

  5. hdu 5280 贪心 O(n)算法

    题意给你一个序列A[1...N],你必须修改一个A[i]为P,使得修改后的序列A的连续最大和最大 其中N<=1000 分析,N非常小,N^2暴力随便做,不细讲 说一个O(N)的算法 我们知道O( ...

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

  7. Bestcoder Round 47 && 48

    1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...

  8. hdu 1038 Biker&#39;s Trip Odometer(水题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1038 Biker's Trip Odometer Time Limit: 2000/1000 MS ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. BZOJ1911:[Apio2010]特别行动队——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1911 又是一个显然的dp……好吧我懒得讲了. s[i]是战斗力前缀和. 我们仍然设k<j< ...

  2. 函数strcpy的实现

    strcpy函数的百科中给出了各种情况的详细说明,这里,仅给出一些注意事项: 1.strcpy的函数原型是: /* dest(destination)为目标字符串,src(source)为原字符串*/ ...

  3. de4dot 用法

    使用de4dot反混淆一下 用法 de4dot -f input.dll -o output.dll

  4. 20181015 考试记录&数论

    题目传送门 W神爷的题解 数论 小 M 的算式 [问题描述] 小 M 在做数学作业的时候遇到了一个有趣的问题:有一个长度为 n 的数字 串 S,小 M 需要在数字之间填入若干个“+”和恰好一个“=”, ...

  5. 从MYSQL数据库查出指定格式的日期

    1.用SQL语言控制: 格式如下: select DATE_FORMAT(t.startTime,"%Y-%m-%d %H:%i") AS startTime, DATE_FORM ...

  6. 背景建模技术(四):视频分析(VideoAnalysis)模块

    视频分析模块主要包含两个函数,一个是VideoAnalysis::setup(....),其主要功能就是确定测试的视频是视频文件或摄像头输入亦或是采用命令行参数:第二个函数是VideoAnalysis ...

  7. Leetcode 001. 两数之和(扩展)

    1.题目要求 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 2.解法一:暴力法(for*for,O(n*n)) ...

  8. Anaconda创建python(2.7/3.6)的虚拟环境后需要添加ipykernel

    今天在工作的过程中遇到这样一个问题:安装完Anaconda利用conda创建了虚拟环境,但是启动jupyter notebook之后却找不到虚拟环境中的python kernel.后来上网找到了解决办 ...

  9. ZooKeeper JMX(十一)

    JMX ZooKeeper对JMX有额外的支持,允许你查看和管理Zk群集. 这个文档假设你对JMX有基本的了解.参考Sun JMX Technology来对JMX进行入门. 关于安装一个本地和远端管理 ...

  10. 自己实现KNN算法

    import numpy as np from math import sqrt from collections import Counter class KNNClassifier(object) ...