Hdu 5586 Sum

简介:

Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 287    Accepted Submission(s): 177


Problem Description
There is a number sequence  A1,A2....An,you can select a interval [l,r] or not,all the numbers  Ai(lir) 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 sum?
 

Input
There are multiple test cases.
First line of each case contains a single integer n. (1n105)
Next line contains n integers  A1,A2....An. (0Ai104)
It's guaranteed that  n106.
 

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
 
题目大意:
给n个数{A}_{1},{A}_{2}....{A}_{n}A1,A2....An,你可以选择一个区间(也可以不选),区间里每个数x变成f(x),其中f(x)=(1890x+143) mod 10007f(x)=(1890x+143)mod10007。问最后n个数之和最大可能为多少。
解题思路:
就是比较一下大小就行了,但是是减去arr[i]的值。。。

代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e5+5;
const int mod = 1e4+7;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
LL gcd(LL a, LL b)
{
    if(b == 0)
        return a;
    return gcd(b, a%b);
}
int arr[maxn], data[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        LL sum = 0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&arr[i]);
            sum += arr[i];
            data[i] = ((arr[i]*1890+143)%mod) - arr[i];
        }
        LL Max = 0, tmp = 0;
        for(int i=0; i<n; i++)
        {
            tmp += data[i];
            if(tmp > Max)
                Max = tmp;
            if(tmp < 0)
                tmp = 0;
        }
        LL ret = sum+Max;
        printf("%I64d\n",ret);
    }
    return 0;
}


目录
相关文章
|
7月前
|
人工智能 Java
HDU-1003- Max Sum (动态规划)
HDU-1003- Max Sum (动态规划)
43 0
|
Go
HDOJ(HDU) 1977 Consecutive sum II(推导、、)
HDOJ(HDU) 1977 Consecutive sum II(推导、、)
112 0
HDOJ(HDU) 2148 Score(比较、)
HDOJ(HDU) 2148 Score(比较、)
107 0
|
人工智能
HDOJ/HDU 2710 Max Factor(素数快速筛选~)
HDOJ/HDU 2710 Max Factor(素数快速筛选~)
108 0
|
存储 人工智能 算法
HDU 1024 Max Sum Plus Plus【动态规划求最大M子段和详解 】
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29942    Accepted Submissio...
2405 0
|
人工智能 Java
HDU 1003 Max Sum【动态规划求最大子序列和详解 】
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 250714    Accepted Submission(s): 593...
1279 0