首页 > 其他 > 详细

hdu 5280 Senior's Array

时间:2015-07-12 23:10:41      阅读:317      评论:0      收藏:0      [点我收藏+]

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5280    

Senior‘s Array

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\leq n\leq 1000$, $-10^9\leq A[i], P\leq 10^9$。

Output

For each test case, output one integer which means the most beautiful interval‘s beauty after your change.

2
3 5
1 -1 2
3 -2
1 -1 2

Sample Output

8
2

数据才1000直接暴力。。

技术分享
 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<map>
 8 using std::max;
 9 using std::cin;
10 using std::cout;
11 using std::endl;
12 using std::find;
13 using std::sort;
14 using std::map;
15 using std::pair;
16 using std::vector;
17 using std::multimap;
18 #define pb(e) push_back(e)
19 #define sz(c) (int)(c).size()
20 #define mp(a, b) make_pair(a, b)
21 #define all(c) (c).begin(), (c).end()
22 #define iter(c) decltype((c).begin())
23 #define cls(arr,val) memset(arr,val,sizeof(arr))
24 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
25 #define rep(i, n) for (int i = 1; i <= (int)(n); i++)
26 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
27 const int N = 1010;
28 const int INF = 0x7fffffff;
29 typedef long long ll;
30 ll p, ans, arr[N], sum[N];
31 int main() {
32 #ifdef LOCAL
33     freopen("in.txt", "r", stdin);
34     freopen("out.txt", "w+", stdout);
35 #endif
36     int t, n;
37     scanf("%d", &t);
38     while (t--) {
39         ans =  -INF;
40         scanf("%d %lld", &n, &p);
41         rep(i, n) scanf("%lld", &arr[i]);
42         rep(i, n) {
43             ll tmp = arr[i]; arr[i] = p;
44             rep(j, n) {
45                 sum[j] = sum[j - 1] > 0 ? sum[j - 1] + arr[j] : arr[j];
46                 ans = max(ans, sum[j]);
47             }
48             arr[i] = tmp;
49         }
50         printf("%lld\n", ans);
51     }
52     return 0;
53 }
View Code

hdu 5280 Senior's Array

原文:http://www.cnblogs.com/GadyPu/p/4641675.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!