HDU 5280 BestCoder Round#47 1001 ---枚举+dp
来源:互联网 发布:mac自带的php环境 编辑:程序博客网 时间:2024/05/29 16:44
Senior's Array
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)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 ofA 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).
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
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 integersn 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 。
In each case, the first line contains two integers
The next line contains the original array.
Output
For each test case, output one integer which means the most beautiful interval's beauty after your change.
Sample Input
23 51 -1 23 -21 -1 2
Sample Output
82
Source
BestCoder Round #47 ($)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5280
对于数组每一个元素换成p;在计算数列和最大值即可。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5280
对于数组每一个元素换成p;在计算数列和最大值即可。
#include <iostream>using namespace std;long long a[1100],n;long long dp[1100];long long unit(){ long long sum=a[0]; dp[0]=a[0]; for(int i=1; i<n; i++) { if(dp[i-1]+a[i]>a[i]) { dp[i]=a[i]+dp[i-1]; } else { dp[i]=a[i]; } if(sum<dp[i]) sum=dp[i]; } return sum;}int main(){ long long t,p; cin>>t; while(t--) { cin>>n>>p; for(int i=0; i<n; i++) { cin>>a[i]; } long long ans=-1000000000001; for(int i=0;i<n;i++) { long long tmp=a[i]; a[i]=p; long long x; x=unit(); ans=max(ans,x); a[i]=tmp; } cout<<ans<<endl; } return 0;}
0 0
- HDU 5280 BestCoder Round#47 1001 ---枚举+dp
- HDU 5280 BestCoder Round#47 1001
- BestCoder Round #92【map,枚举,DP】
- HDU 5280 BestCoder Round #47 1001:Senior's Array
- HDU BestCoder Round #48 1001
- HDU 5778 BestCoder Round #85 abs (暴力枚举)
- BestCoder Round #47 ($) HDU 5280 Senior\'s Array
- HDU 4907 - Task schedule(BestCoder Round #3 简单DP)
- hdu 5617 Jam's maze(dp)(BestCoder Round #70)
- HDU 5656 CA Loves GCD (BestCoder Round #78) DP
- HDU 5779 BestCoder Round #85 Tower Defence ( dp升级版 )
- hdu 5945 (dp+单调队列,BestCoder Round #89)
- HDU 5281 BestCoder Round #47 1002
- BestCoder round#3 1001 && Hdu 4907
- hdu 4989 Summary(BestCoder Round #8 1001)
- BestCoder Round #16 1001(hdu 5086)
- BestCoder Round #49 ($) HDU 5339 Untitled(1001)
- BestCoder Round #84 1001 hdu 5747 模拟
- android ExpandableListView二级列表
- [2015年7月][13~18][poj2823, 项目问题解决]
- UPUPW_NGINX_PHP5.3.29_1504.7z的问题 REQUEST 数字的时候,有时候会失效
- ClearCase命令mkbl的描述
- 跨域访问实现依据
- HDU 5280 BestCoder Round#47 1001 ---枚举+dp
- mvc框架
- C语言--程序设计基础1—3章
- 黑马程序员——Java包、内部类、Object类
- Two Sum
- UVALive 6953Digi Comp II(搜索)
- Android 输入管理服务-输入事件到达之后的处理流程
- 知识点——操作系统
- MySql笔记(第一弹:MySql的安装)