HDU 5280 Senior's Array(DP思想 暴力)
来源:互联网 发布:买个淘宝店 编辑:程序博客网 时间:2024/05/23 19:20
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
题意:将数组中的一个数替换成p,使得替换后的数组的区间和最大,输出最大的区间和。
没什么难度,理解题意就会发现是求替换后的子序列的最大和,数据范围不大,可以直接借用DP的思想,直接暴力,过程中维护最大值。
AC代码:
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define N 1005 long long a[N]; long long dp[N]; int main() { long long x; scanf("%lld",&x); while(x--) { long long i,j,m,n; long long M=-0x3f3f3f3f; scanf("%lld%lld",&m,&n); for(i=1;i<=m;i++) { scanf("%lld",&a[i]); } memset(dp,0,sizeof(dp)); for(i=1;i<=m;i++) { int t=a[i]; a[i]=n; for(j=1;j<=m;j++) { dp[j]=max(a[j],dp[j-1]+a[j]); M=max(M,dp[j]); } a[i]=t; } printf("%lld\n",M); } return 0; }
0 0
- HDU 5280 Senior's Array(DP思想 暴力)
- hdu 5280 Senior's Array(dp)
- 杭电 hdu 5280 Senior's Array(dp)
- HDU 5280 Senior's Array
- hdu 5280 Senior's Array
- HDU 5280 Senior's Array
- hdu 5280 Senior's Array
- HDU 5280 Senior's Array
- HDU 5280 Senior's Array
- Senior's Array(5280)
- HDU 5280 BestCoder Round #47 1001:Senior's Array
- hdu 5280 Senior's Array 修改区间和最大
- HDU 5280 Senior's Array 最大区间和
- BestCoder Round #47 ($) HDU 5280 Senior\'s Array
- HDU5280 Senior's Array(简单DP)
- hdu 5282 Senior's String 两次dp
- [dp] hdu 5282 Senior's String
- hdu 5281 Senior's Gun(贪心)
- XML文件解析
- spring动态创建切换数据源动态之原理
- SVN分支/合并原理及最佳实践
- Linux配置LNMP环境搭建
- java 枚举
- HDU 5280 Senior's Array(DP思想 暴力)
- Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey区别
- python 与sqlite3
- DAO和DTO的区别
- notification全解和工具类
- Android 用StaticLayout和SpannableString实现歌词逐字更新
- 简单的调用系统摄像头和相机保存到Sd卡的Demo
- mongoDB学习笔记六
- mycat 简单的配置数据库分片(一)