SUM
Description
There is a number sequence ,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 .
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
题意:
给出一个序列,允许把其中某一连续段的所有值变成这个数对应的某个函数的值,只允许操作一次,问得到的最终序列的和最大为多少
题解:
找出一个数组,储存每一个数字经过函数运算后变成的数与原来这个数的差值,,对这个数组求最大连续子序列的和,然后加上原来数组的总和即为所求
比赛的时候确实脑残了,本来自己会的知识点,就稍微转化了一下,自己竟然没分析出来,真心怀疑人生了.....
学会的东西想要达到灵活运用,真的是好难啊..
/* http://blog.csdn.net/liuke19950717 */ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const ll maxn=1e5+5; const ll mod=10007; ll x[maxn],y[maxn]; ll max_sum(ll num[],ll n) { ll ans=0,tp=0; for(ll i=0;i<n;++i) { tp+=num[i]; if(tp<0) { tp=0; } ans=max(ans,tp); } return ans; } int main() { ll n; while(~scanf("%lld",&n)) { ll ans=0; for(ll i=0;i<n;++i) { scanf("%lld",&x[i]); y[i]=(1890*x[i]+143)%mod-x[i]; ans+=x[i]; } printf("%lld\n",ans+max_sum(y,n)); } return 0; }
时间: 2024-10-10 05:51:36