码迷,mamicode.com
首页 > 其他好文 > 详细

Hdu 5586 sum【最大连续子序列和】

时间:2016-04-29 17:04:53      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

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;
}


Hdu 5586 sum【最大连续子序列和】

标签:

原文地址:http://blog.csdn.net/liuke19950717/article/details/51252693

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!