Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 507 Accepted Submission(s): 284
Problem Description
There is a number sequence A
1
,A
1
,A
1
,A
1
,A
1
,A
1
,
,you can select a interval [l,r] or not,all the numbers
will become
.
.After that,the sum of n numbers should be as much as possible.What is the maximum sum?
,you can select a interval [l,r] or not,all the numbers
will become
.
.After that,the sum of n numbers should be as much as possible.What is the maximum sum?
Input
There are multiple test cases. First line of each case contains a single integer n.
Next line contains n integers
.
It's guaranteed that
.
Next line contains n integers
.
It's guaranteed that
.
Output
For each test case,output the answer in a line.
Sample Input
2
10000 9999
5
1 9999 1 9999 1
Sample Output
19999
22033
Source
传送门 http://acm.hdu.edu.cn/showproblem.php?pid=5586
类似杭电1003
题意 一串序列 可以只能更改一个区间 或不更改f 更改操作为f(x)=(1890x+143)mod10007
询问 这串序列的和的最大值
做一个变形 每个值变为 f(x)-x 然后按照1003的方法 求最大连续区间的和
dp[i]=max(dp[i],dp[i-1]+dp[i]);
f
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
int bac(int s)
{
return (1890*s+143)%10007;
}
int b[100005],a[100005];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(b,0,sizeof(b));
memset(a,0,sizeof(a));
int re=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
re=re+a[i];
b[i]=bac(a[i])-a[i];
}
// int exm=0;
int maxn=0;
for(int i=1;i<n;i++)
{
if(b[i]+b[i-1]>b[i])
b[i]=b[i]+b[i-1];
if(b[i]>maxn)
maxn=b[i];
}
printf("%d
",re+maxn);
}
return 0;
}