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

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

Hdu 5586 sum【最大连续子序列和】的相关文章

HDU 1003 Max Sum 最大连续子序列的和

Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. Input The first line of the input contains

HDU 1231:最大连续子序列(DP)

最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18461    Accepted Submission(s): 8202 Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j

hdu 5586 Sum(dp+技巧)

Problem Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r) will become f(Ai).f(x)=(1890x+143)mod10007.After that,the sum of n numbers should be as much as possible.What is the maximum s

hdu 5586 Sum【dp最大子段和】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 677    Accepted Submission(s): 358 Problem Description There is a number sequence A1,A2...

杭电1003 Max Sum 【连续子序列求最大和】

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目意思: 即给出一串数据,求连续的子序列的最大和 解题思路: 因为我们很容易想到用一个max来存放找到的子序列的和中的最大值,通过不断比较,对max的值进行更新,最后我们就能够得到最大子序列的和,于是很容易想到用暴力搜索,见上一篇博客,这样的时间复杂度为O(n^3),是超时的. 又因为想到只要一个数不是负数,不管它再小,加上去也是会使和变大的,所以我们需要用另一个变量来判断即将要加上的一个

hdu 5586 Sum 最大子段和

Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5586 Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r) will become f(Ai).f(x)=(1890x+143)mod1

zoj1003-Max Sum (最大连续子序列之和)

http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 161361    Accepted Submission(s): 37794 Problem Description Given a sequence a[1],a[2],a[3]

HDU 5586 Sum

最大子串和 #include<cstdio> #include<cstring> const int maxn=100000+10; int n; int x[maxn]; int fx[maxn]; int a[maxn]; int sum[maxn]; int L[maxn],R[maxn]; const int INF=0x7FFFFFFF; int max(int a,int b) { if(a>b) return a; return b; } int main()

hdu 5586 Sum 基础dp

Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r) will become f(Ai).f(x)=(1890x+143)mod1