标签:dp
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);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:dp
原文地址:http://blog.csdn.net/u010372095/article/details/46849269